aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrunchy <crunchy>2003-06-27 13:40:23 +0000
committercrunchy <crunchy>2003-06-27 13:40:23 +0000
commitb5f5847bedf884611a9978236bb66d150016c71e (patch)
treed14e220039dba60b90fd9f9909aff7a7cb20079d
parentc6c22c4fadb3000453389f3ecf471392674adfd1 (diff)
downloadmpiosh-b5f5847bedf884611a9978236bb66d150016c71e.tar.gz
mpiosh-b5f5847bedf884611a9978236bb66d150016c71e.tar.bz2
mpiosh-b5f5847bedf884611a9978236bb66d150016c71e.zip
tested and hopefully fixed the backup and restore commands
-rw-r--r--ChangeLog9
-rwxr-xr-xautogen.sh2
-rw-r--r--mpiosh/callback.c99
-rw-r--r--mpiosh/config.c17
-rw-r--r--mpiosh/config.h4
5 files changed, 85 insertions, 46 deletions
diff --git a/ChangeLog b/ChangeLog
index df3b46d..9c27c1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2003-06-27 Andreas Buesching <crunchy@tzi.de>
+ * 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 <crunchy@tzi.de>
+
* mpiosh/global.c: add CONFIG_BACKUP defining a user backup
directory.
(commands): add backup and restore command
diff --git a/autogen.sh b/autogen.sh
index f0bc897..a92008e 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -5,6 +5,8 @@
# Andreas Buesching <crunchy@tzi.de>
# $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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -27,6 +27,8 @@
#include <grp.h>
#include <pwd.h>
#include <regex.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -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