diff options
author | Milan Crha <mcrha@redhat.com> | 2009-06-22 23:09:21 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2009-06-22 23:09:21 +0800 |
commit | 7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf (patch) | |
tree | 3aca18c7f9691569334205f1ce41b521d3cf8adf | |
parent | d38e8b65dbbcf20ccbdc9ffd73830fd1725f91c6 (diff) | |
download | gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.tar gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.tar.gz gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.tar.bz2 gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.tar.lz gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.tar.xz gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.tar.zst gsoc2013-evolution-7a9ab4f23b918dbf4fd0790f002924dc7c18a0cf.zip |
Bug #566369 - backup-restore - recognize broken archive
-rw-r--r-- | plugins/backup-restore/backup-restore.c | 8 | ||||
-rw-r--r-- | plugins/backup-restore/backup.c | 76 |
2 files changed, 64 insertions, 20 deletions
diff --git a/plugins/backup-restore/backup-restore.c b/plugins/backup-restore/backup-restore.c index e550851762..b4f0d98011 100644 --- a/plugins/backup-restore/backup-restore.c +++ b/plugins/backup-restore/backup-restore.c @@ -55,18 +55,18 @@ static void backup (const gchar *filename, gboolean restart) { if (restart) - execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--backup", "--restart", filename, NULL); + execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--backup", "--restart", filename, (char *)NULL); else - execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--backup", filename, NULL); + execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--backup", filename, (char *)NULL); } static void restore (const gchar *filename, gboolean restart) { if (restart) - execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--restore", "--restart", filename, NULL); + execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--restore", "--restart", filename, (char *)NULL); else - execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--restore", filename, NULL); + execl (EVOLUTION_TOOLSDIR "/evolution-backup", "evolution-backup", "--gui", "--restore", filename, (char *)NULL); } static gboolean diff --git a/plugins/backup-restore/backup.c b/plugins/backup-restore/backup.c index 92adb2d7a4..7842606a72 100644 --- a/plugins/backup-restore/backup.c +++ b/plugins/backup-restore/backup.c @@ -51,11 +51,11 @@ static gchar *chk_file = NULL; static gboolean restart_arg = FALSE; static gboolean gui_arg = FALSE; static gchar **opt_remaining = NULL; -static gint result=0; +static gint result = 0; static GtkWidget *progress_dialog; static GtkWidget *pbar; static gchar *txt = NULL; -gboolean complete = FALSE; +static gboolean complete = FALSE; static GOptionEntry options[] = { { "backup", '\0', 0, G_OPTION_ARG_NONE, &backup_op, @@ -76,9 +76,11 @@ static GOptionEntry options[] = { #define d(x) #define print_and_run(x) G_STMT_START { g_message ("%s", x); system (x); } G_STMT_END - #define CANCEL(x) if (x) return; +static gboolean check (const gchar *filename); + + static GString * replace_string (const gchar *text, const gchar *find, const gchar *replace) { @@ -228,6 +230,20 @@ restore (const gchar *filename) gchar *quotedfname; g_return_if_fail (filename && *filename); + + if (!check (filename)) { + g_message ("Cannot restore from an incorrect archive '%s'.", filename); + + if (restart_arg) { + CANCEL (complete); + txt = _("Restarting Evolution"); + complete=TRUE; + run_cmd (EVOLUTION); + } + + return; + } + quotedfname = g_shell_quote(filename); /* FIXME Will the versioned setting always work? */ @@ -273,38 +289,51 @@ restore (const gchar *filename) } -static void +static gboolean check (const gchar *filename) { gchar *command; gchar *quotedfname; - g_return_if_fail (filename && *filename); + g_return_val_if_fail (filename && *filename, FALSE); quotedfname = g_shell_quote(filename); - command = g_strdup_printf ("tar ztf %s | grep -e \"^\\.evolution/$\"", quotedfname); + command = g_strdup_printf ("tar ztf %s 1>/dev/null", quotedfname); result = system (command); g_free (command); g_message ("First result %d", result); - if (result) - exit (result); + if (result) { + g_free (quotedfname); + return FALSE; + } + + command = g_strdup_printf ("tar ztf %s | grep -e \"^\\.evolution/$\"", quotedfname); + result = system (command); + g_free (command); + + g_message ("Second result %d", result); + if (result) { + g_free (quotedfname); + return FALSE; + } command = g_strdup_printf ("tar ztf %s | grep -e \"^\\.evolution/%s$\"", quotedfname, GCONF_DUMP_FILE); result = system (command); g_free (command); g_free (quotedfname); - g_message ("Second result %d", result); + g_message ("Third result %d", result); + return result != 0; } static gboolean -pbar_update() +pbar_update (gpointer data) { if (!complete) { - gtk_progress_bar_pulse ((GtkProgressBar *)pbar); - gtk_progress_bar_set_text ((GtkProgressBar *)pbar, txt); + gtk_progress_bar_pulse ((GtkProgressBar *)pbar); + gtk_progress_bar_set_text ((GtkProgressBar *)pbar, txt); return TRUE; } @@ -334,7 +363,7 @@ idle_cb(gpointer data) if (gui_arg) { /* Show progress dialog */ - gtk_progress_bar_pulse ((GtkProgressBar *)pbar); + gtk_progress_bar_pulse ((GtkProgressBar *)pbar); g_timeout_add (50, pbar_update, NULL); } @@ -356,6 +385,21 @@ dlg_response (GtkWidget *dlg, gint response, gpointer data) /* We will kill just the tar operation. Rest of the them will be just a second of microseconds.*/ run_cmd ("pkill tar"); + if (bk_file && backup_op && response == GTK_RESPONSE_REJECT) { + /* backup was canceled, delete the backup file as it is not needed now */ + gchar *cmd, *filename; + + g_message ("Backup cancelled, removing partial backup file."); + + filename = g_shell_quote (bk_file); + cmd = g_strconcat ("rm ", filename, NULL); + + run_cmd (cmd); + + g_free (cmd); + g_free (filename); + } + gtk_main_quit (); } @@ -495,9 +539,9 @@ main (gint argc, gchar **argv) g_signal_connect (progress_dialog, "response", G_CALLBACK(dlg_response), NULL); gtk_widget_show_all (progress_dialog); } else if (check_op) { - /* For sanity we don't need gui */ - check (chk_file); - exit (result); + /* For sanity we don't need gui */ + check (chk_file); + exit (result == 0 ? 0 : 1); } g_idle_add (idle_cb, NULL); |