aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrunchy <crunchy>2003-06-27 12:21:21 +0000
committercrunchy <crunchy>2003-06-27 12:21:21 +0000
commitc6c22c4fadb3000453389f3ecf471392674adfd1 (patch)
tree8e9b5720b0c8474226dae99decfbd4c82f657d8d
parent021de49f8e3d1c3b9f8e6e13df0ee7f2552c7b7a (diff)
downloadmpiosh-c6c22c4fadb3000453389f3ecf471392674adfd1.tar.gz
mpiosh-c6c22c4fadb3000453389f3ecf471392674adfd1.tar.bz2
mpiosh-c6c22c4fadb3000453389f3ecf471392674adfd1.zip
add backup and restore commands; little bug fix and clean up. Need to be tested! Just give me 5 minutes, please!
-rw-r--r--ChangeLog19
-rw-r--r--libmpio/src/mpio.c15
-rw-r--r--mpiosh/callback.c93
-rw-r--r--mpiosh/callback.h6
-rw-r--r--mpiosh/config.c24
-rw-r--r--mpiosh/config.h5
-rw-r--r--mpiosh/global.c9
-rw-r--r--mpiosh/global.h5
8 files changed, 160 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index c9377f5..df3b46d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+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
+
+ * libmpio/src/mpio.c (mpio_file_get_real): fix a bug. Unlink the
+ external file (not the internal) before writing it (is it really
+ necessary?).
+
+ * mpiosh/callback.c (mpiosh_cmd_config): deactivated.
+ (mpiosh_cmd_backup): new function, which creates a backup of all
+ existing config files.
+ (mpiosh_cmd_restore): new function, which restores a backup.
+
+ * mpiosh/config.c (mpiosh_config_check_backup_dir): new function
+ to check for the backup directory ~/.mpio/backup/. Optionally it
+ can be created.
+
2003-06-26 Markus Germeier <mager@tzi.de>
* libmpio/src/mpio.c (mpio_file_exists):
added helper function
diff --git a/libmpio/src/mpio.c b/libmpio/src/mpio.c
index 1dfa192..146b12e 100644
--- a/libmpio/src/mpio.c
+++ b/libmpio/src/mpio.c
@@ -1,5 +1,5 @@
/*
- * $Id: mpio.c,v 1.5 2003/06/26 19:53:58 germeier Exp $
+ * $Id: mpio.c,v 1.6 2003/06/27 12:21:21 crunchy Exp $
*
* libmpio - a library for accessing Digit@lways MPIO players
* Copyright (C) 2002, 2003 Markus Germeier
@@ -555,13 +555,12 @@ mpio_file_get_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
if (f && p) {
filesize=fsize=mpio_dentry_get_filesize(m, mem, p);
- if (memory)
- {
- *memory = malloc(filesize);
- } else {
- unlink(filename);
- fd = open(as, (O_RDWR | O_CREAT), (S_IRWXU | S_IRGRP | S_IROTH));
- }
+ if (memory) {
+ *memory = malloc(filesize);
+ } else {
+ unlink( as );
+ fd = open(as, (O_RDWR | O_CREAT), (S_IRWXU | S_IRGRP | S_IROTH));
+ }
do
{
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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -834,6 +834,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[])
{
BYTE *config_data;
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
*
@@ -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 <crunchy@tzi.de>
*
- * $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 <crunchy@tzi.de>
+ * Copyright (C) 2001-2003 Andreas Büsching <crunchy@tzi.de>
*
* 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;