From b5f5847bedf884611a9978236bb66d150016c71e Mon Sep 17 00:00:00 2001 From: crunchy Date: Fri, 27 Jun 2003 13:40:23 +0000 Subject: tested and hopefully fixed the backup and restore commands --- ChangeLog | 9 +++++ autogen.sh | 2 ++ mpiosh/callback.c | 99 +++++++++++++++++++++++++++++++++++-------------------- mpiosh/config.c | 17 +++++----- mpiosh/config.h | 4 +-- 5 files changed, 85 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index df3b46d..9c27c1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-06-27 Andreas Buesching + + * mpiosh/callback.c (mpiosh_cmd_backup): using the resolved backup + directory name as argument for mpio_file_get_as + (mpiosh_cmd_restore): same as above s/get/put/ + + * mpiosh/config.c (mpiosh_config_check_backup_dir): changed return + type to char *. returning the resolved backip directory name + 2003-06-27 Andreas Buesching * mpiosh/global.c: add CONFIG_BACKUP defining a user backup diff --git a/autogen.sh b/autogen.sh index f0bc897..a92008e 100755 --- a/autogen.sh +++ b/autogen.sh @@ -5,6 +5,8 @@ # Andreas Buesching # $id$ +export WANT_AUTOMAKE="1.7" + aclocal && autoconf && automake -a && ./configure $@ # end of autogen.sh diff --git a/mpiosh/callback.c b/mpiosh/callback.c index daf99a0..90eeec7 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.c,v 1.43 2003/06/27 12:21:21 crunchy Exp $ + * $Id: callback.c,v 1.44 2003/06/27 13:40:23 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -838,87 +840,114 @@ mpiosh_cmd_backup(char *args[]) { int size; char filename[ 1024 ]; + char *path; UNUSED(args); MPIOSH_CHECK_CONNECTION_CLOSED; - if ( !mpiosh_config_check_backup_dir( mpiosh.config, TRUE ) ) { + path = mpiosh_config_check_backup_dir( mpiosh.config, TRUE ); + + if ( !path ) { fprintf( stderr, "error: could not create backup directory: %s\n", - CONFIG_BACKUP ); - return; + path ); + goto cleanup_backup; } - - snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CONFIG_FILE ); + + printf( "backup %s ...\n", MPIO_CONFIG_FILE ); + snprintf( filename, 1024, "%s%s", path, 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 == -1 ) goto cleanup_backup; if ( !size ) debugn (1, "file does not exist: %s\n", MPIO_CONFIG_FILE ); - snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CHANNEL_FILE ); + + if ( mpio_file_exists( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CHANNEL_FILE ) ) + printf( "backup %s ...\n", MPIO_CHANNEL_FILE ); + snprintf( filename, 1024, "%s%s", path, 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 == -1 ) goto cleanup_backup; if ( !size ) debugn (2, "file does not exist: %s\n", MPIO_CHANNEL_FILE ); - snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_FONT_FON ); + if ( mpio_file_exists( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_FONT_FON ) ) + printf( "backup %s ...\n", MPIO_FONT_FON ); + snprintf( filename, 1024, "%s%s", path, 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 == -1 ) goto cleanup_backup; if ( !size ) debugn (2, "file does not exist: %s\n", MPIO_FONT_FON ); + + cleanup_backup: + free( path ); + printf("\n"); } void mpiosh_cmd_restore(char *args[]) { int size; - char filename[ 1024 ]; - + char filename[ 1024 ], answer[ 512 ]; + char *path; + UNUSED(args); MPIOSH_CHECK_CONNECTION_CLOSED; - if ( !mpiosh_config_check_backup_dir( mpiosh.config, FALSE ) ) { + path = mpiosh_config_check_backup_dir( mpiosh.config, FALSE ); + + if ( !path ) { fprintf( stderr, "error: there is no backup: %s\n", - CONFIG_BACKUP ); - return; + path ); + goto cleanup_restore; } + + printf( "This will destroy the current configuration of your player. " + "Are you sure you want to restore the backup (y/n)? " ); + + fgets( answer, 511, stdin ); - snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CONFIG_FILE ); - size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM, + if (answer[0] != 'y' && answer[0] != 'Y') + goto cleanup_restore; + + snprintf( filename, 1024, "%s%s", path, MPIO_FONT_FON ); + if ( mpio_file_exists( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_FONT_FON ) ) + mpio_file_del( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_FONT_FON, NULL ); + 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 ); + MPIO_FONT_FON, + FTYPE_FONT, mpiosh_callback_put ); + mpio_file_move( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_FONT_FON, NULL ); + + snprintf( filename, 1024, "%s%s", path, MPIO_CHANNEL_FILE ); + if ( mpio_file_exists( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CHANNEL_FILE ) ) + mpio_file_del( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CHANNEL_FILE, NULL ); 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 ); + mpio_file_move( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CHANNEL_FILE, NULL ); - snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_FONT_FON ); - size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM, + snprintf( filename, 1024, "%s%s", path, MPIO_CONFIG_FILE ); + if ( mpio_file_exists( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CONFIG_FILE ) ) + mpio_file_del( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CONFIG_FILE, NULL ); + 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 ); + MPIO_CONFIG_FILE, + FTYPE_CONF, mpiosh_callback_put ); + mpio_file_move( mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CONFIG_FILE, NULL ); + + cleanup_restore: + free( path ); } diff --git a/mpiosh/config.c b/mpiosh/config.c index e962266..931f785 100644 --- a/mpiosh/config.c +++ b/mpiosh/config.c @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: config.c,v 1.6 2003/06/27 12:21:21 crunchy Exp $ + * $Id: config.c,v 1.7 2003/06/27 13:40:23 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -166,23 +166,22 @@ mpiosh_config_read(struct mpiosh_config_t *config) return 1; } -int +char * mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ) { DIR *dir; char *path = cfg_resolve_path( CONFIG_BACKUP ); - int ret = 1; + char *ret = path; if ( ( dir = opendir( path ) ) == NULL ) - if ( create ) - ret = ( ! mkdir(path, 0777 ) ); - else - ret = 0; + if ( create ) { + if ( mkdir(path, 0777 ) ) + ret = NULL; + } else + ret = NULL; else closedir(dir); - free(path); - return ret; } diff --git a/mpiosh/config.h b/mpiosh/config.h index 81c88e1..091e61a 100644 --- a/mpiosh/config.h +++ b/mpiosh/config.h @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: config.h,v 1.4 2003/06/27 12:21:21 crunchy Exp $ + * $Id: config.h,v 1.5 2003/06/27 13:40:23 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -47,7 +47,7 @@ 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, +char * mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ); #endif -- cgit v1.2.3