From c6c22c4fadb3000453389f3ecf471392674adfd1 Mon Sep 17 00:00:00 2001 From: crunchy Date: Fri, 27 Jun 2003 12:21:21 +0000 Subject: add backup and restore commands; little bug fix and clean up. Need to be tested! Just give me 5 minutes, please! --- mpiosh/callback.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- mpiosh/callback.h | 6 +++- mpiosh/config.c | 24 ++++++++++++-- mpiosh/config.h | 5 ++- mpiosh/global.c | 9 +++++- mpiosh/global.h | 5 +-- 6 files changed, 134 insertions(+), 8 deletions(-) (limited to 'mpiosh') diff --git a/mpiosh/callback.c b/mpiosh/callback.c index 70c2e5a..daf99a0 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.c,v 1.42 2003/06/26 19:53:58 germeier Exp $ + * $Id: callback.c,v 1.43 2003/06/27 12:21:21 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -833,6 +833,96 @@ mpiosh_cmd_health(char *args[]) } +void +mpiosh_cmd_backup(char *args[]) +{ + int size; + char filename[ 1024 ]; + + UNUSED(args); + + MPIOSH_CHECK_CONNECTION_CLOSED; + + if ( !mpiosh_config_check_backup_dir( mpiosh.config, TRUE ) ) { + fprintf( stderr, "error: could not create backup directory: %s\n", + CONFIG_BACKUP ); + return; + } + + snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CONFIG_FILE ); + size = mpio_file_get_as( mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_CONFIG_FILE, + filename, + mpiosh_callback_get ); + if ( size == -1 ) return; + if ( !size ) + debugn (1, "file does not exist: %s\n", MPIO_CONFIG_FILE ); + + snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CHANNEL_FILE ); + size = mpio_file_get_as( mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_CHANNEL_FILE, + filename, + mpiosh_callback_get ); + if ( size == -1 ) return; + if ( !size ) + debugn (2, "file does not exist: %s\n", MPIO_CHANNEL_FILE ); + + snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_FONT_FON ); + size = mpio_file_get_as( mpiosh.dev, MPIO_INTERNAL_MEM, + MPIO_FONT_FON, + filename, + mpiosh_callback_get ); + if ( size == -1 ) return; + if ( !size ) + debugn (2, "file does not exist: %s\n", MPIO_FONT_FON ); +} + +void +mpiosh_cmd_restore(char *args[]) +{ + int size; + char filename[ 1024 ]; + + UNUSED(args); + + MPIOSH_CHECK_CONNECTION_CLOSED; + + if ( !mpiosh_config_check_backup_dir( mpiosh.config, FALSE ) ) { + fprintf( stderr, "error: there is no backup: %s\n", + CONFIG_BACKUP ); + return; + } + + snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CONFIG_FILE ); + size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM, + filename, + MPIO_CONFIG_FILE, + FTYPE_CONF, mpiosh_callback_put ); + if ( size == -1 ) return; + if ( !size ) + debugn (1, "file does not exist: %s\n", MPIO_CONFIG_FILE ); + + snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CHANNEL_FILE ); + size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM, + filename, + MPIO_CHANNEL_FILE, + FTYPE_CHAN, mpiosh_callback_put ); + if ( size == -1 ) return; + if ( !size ) + debugn (2, "file does not exist: %s\n", MPIO_CHANNEL_FILE ); + + snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_FONT_FON ); + size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM, + filename, + MPIO_FONT_FON, + FTYPE_FONT, mpiosh_callback_put ); + if ( size == -1 ) return; + if ( !size ) + debugn (2, "file does not exist: %s\n", MPIO_FONT_FON ); +} + + +#if 0 void mpiosh_cmd_config(char *args[]) { @@ -906,6 +996,7 @@ mpiosh_cmd_config(char *args[]) printf("config [read|write|show] <\n"); } } +#endif void mpiosh_cmd_channel(char *args[]) diff --git a/mpiosh/callback.h b/mpiosh/callback.h index f0e2b61..00ffb86 100644 --- a/mpiosh/callback.h +++ b/mpiosh/callback.h @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.h,v 1.12 2003/06/26 19:53:59 germeier Exp $ + * $Id: callback.h,v 1.13 2003/06/27 12:21:21 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -52,7 +52,11 @@ void mpiosh_cmd_switch(char *args[]); void mpiosh_cmd_rename(char *args[]); void mpiosh_cmd_dump_mem(char *args[]); void mpiosh_cmd_health(char *args[]); +void mpiosh_cmd_backup(char *args[]); +void mpiosh_cmd_restore(char *args[]); +#if 0 void mpiosh_cmd_config(char *args[]); +#endif void mpiosh_cmd_channel(char *args[]); void mpiosh_cmd_id3(char *args[]); void mpiosh_cmd_id3_format(char *args[]); diff --git a/mpiosh/config.c b/mpiosh/config.c index bc2c7dd..e962266 100644 --- a/mpiosh/config.c +++ b/mpiosh/config.c @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: config.c,v 1.5 2003/04/19 11:41:26 germeier Exp $ + * $Id: config.c,v 1.6 2003/06/27 12:21:21 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -167,7 +167,27 @@ mpiosh_config_read(struct mpiosh_config_t *config) } int -mpiosh_config_write(struct mpiosh_config_t *config) +mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ) +{ + DIR *dir; + char *path = cfg_resolve_path( CONFIG_BACKUP ); + int ret = 1; + + if ( ( dir = opendir( path ) ) == NULL ) + if ( create ) + ret = ( ! mkdir(path, 0777 ) ); + else + ret = 0; + else + closedir(dir); + + free(path); + + return ret; +} + +int +mpiosh_config_write( struct mpiosh_config_t *config ) { DIR *dir; char *path = cfg_resolve_path(CONFIG_USER); diff --git a/mpiosh/config.h b/mpiosh/config.h index c7924d4..81c88e1 100644 --- a/mpiosh/config.h +++ b/mpiosh/config.h @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: config.h,v 1.3 2003/04/19 09:32:48 germeier Exp $ + * $Id: config.h,v 1.4 2003/06/27 12:21:21 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -47,6 +47,9 @@ const char *mpiosh_config_read_key(struct mpiosh_config_t *config, int mpiosh_config_read(struct mpiosh_config_t *config); int mpiosh_config_write(struct mpiosh_config_t *config); +int mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, + int create ); + #endif /* end of config.h */ diff --git a/mpiosh/global.c b/mpiosh/global.c index dc4ad45..f589114 100644 --- a/mpiosh/global.c +++ b/mpiosh/global.c @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: global.c,v 1.13 2003/06/26 19:53:59 germeier Exp $ + * $Id: global.c,v 1.14 2003/06/27 12:21:21 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -36,6 +36,7 @@ int mpiosh_cancel_ack = 0; /* configuration filenames */ const char *CONFIG_GLOBAL = SYSCONFDIR "/mpio/"; const char *CONFIG_USER = "~/.mpio/"; +const char *CONFIG_BACKUP = "~/.mpio/backup/"; const char *CONFIG_FILE = "mpioshrc"; const char *CONFIG_HISTORY = "history"; @@ -136,6 +137,12 @@ struct mpiosh_cmd_t commands[] = { " dump FAT, directory, spare area and the first 0x100 of the\n" " selected memory card", mpiosh_cmd_dump_mem, NULL }, + { "backup", NULL, NULL, + " create a backup of all known configuration files.", + mpiosh_cmd_backup, NULL }, + { "restore", NULL, NULL, + " restore an existing backup of all known configuration files.", + mpiosh_cmd_restore, NULL }, #if 0 /* deactivated for the 0.6.0 release because the code is incomplete! -mager */ { "config", (char *[]) { "conf", NULL }, "[read|write|show]", diff --git a/mpiosh/global.h b/mpiosh/global.h index a807c4a..1e52491 100644 --- a/mpiosh/global.h +++ b/mpiosh/global.h @@ -2,9 +2,9 @@ * * Author: Andreas Buesching * - * $Id: global.h,v 1.2 2002/10/29 20:03:35 crunchy Exp $ + * $Id: global.h,v 1.3 2003/06/27 12:21:22 crunchy Exp $ * - * Copyright (C) 2001 Andreas Büsching + * Copyright (C) 2001-2003 Andreas Büsching * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,6 +56,7 @@ extern int mpiosh_cancel_ack; extern const char *CONFIG_GLOBAL; extern const char *CONFIG_USER; +extern const char *CONFIG_BACKUP; extern const char *CONFIG_FILE; extern const char *CONFIG_HISTORY; -- cgit v1.2.3