[evolution/gnome-3-22] Bug 774156 - [backup-restore] Offer .tar.xz if 'xz' available
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-22] Bug 774156 - [backup-restore] Offer .tar.xz if 'xz' available
- Date: Thu, 10 Nov 2016 17:26:11 +0000 (UTC)
commit e71d4b8acd124f0adf3ea30503e02d64ab368480
Author: Milan Crha <mcrha redhat com>
Date: Thu Nov 10 18:23:04 2016 +0100
Bug 774156 - [backup-restore] Offer .tar.xz if 'xz' available
modules/backup-restore/evolution-backup-restore.c | 25 +++++--
modules/backup-restore/evolution-backup-tool.c | 79 +++++++++++++++------
shell/e-shell-utils.c | 2 +
3 files changed, 79 insertions(+), 27 deletions(-)
---
diff --git a/modules/backup-restore/evolution-backup-restore.c
b/modules/backup-restore/evolution-backup-restore.c
index fadb1a1..db5b0f9 100644
--- a/modules/backup-restore/evolution-backup-restore.c
+++ b/modules/backup-restore/evolution-backup-restore.c
@@ -186,7 +186,7 @@ set_local_only (GtkFileChooser *file_chooser)
}
static gchar *
-suggest_file_name (void)
+suggest_file_name (const gchar *extension)
{
time_t t;
struct tm tm;
@@ -195,8 +195,21 @@ suggest_file_name (void)
localtime_r (&t, &tm);
return g_strdup_printf (
- "evolution-backup-%04d%02d%02d.tar.gz",
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
+ "evolution-backup-%04d%02d%02d.tar%s",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ extension);
+}
+
+static gboolean
+is_xz_available (void)
+{
+ gchar *path;
+
+ path = g_find_program_in_path ("xz");
+
+ g_free (path);
+
+ return path != NULL;
}
static void
@@ -209,13 +222,15 @@ action_settings_backup_cb (GtkAction *action,
const gchar *attribute;
GError *error = NULL;
gchar *suggest;
+ gboolean has_xz;
- suggest = suggest_file_name ();
+ has_xz = is_xz_available ();
+ suggest = suggest_file_name (has_xz ? ".xz" : ".gz");
file = e_shell_run_save_dialog (
e_shell_window_get_shell (shell_window),
_("Select name of the Evolution backup file"),
- suggest, "*.tar.gz", (GtkCallback)
+ suggest, has_xz ? "*.tar.xz;*.tar.gz" : "*.tar.gz", (GtkCallback)
set_local_only, NULL);
g_free (suggest);
diff --git a/modules/backup-restore/evolution-backup-tool.c b/modules/backup-restore/evolution-backup-tool.c
index e0ed680..3bf5779 100644
--- a/modules/backup-restore/evolution-backup-tool.c
+++ b/modules/backup-restore/evolution-backup-tool.c
@@ -265,15 +265,30 @@ write_dir_file (void)
g_string_free (content, TRUE);
}
+static gboolean
+get_filename_is_xz (const gchar *filename)
+{
+ gint len;
+
+ if (!filename)
+ return FALSE;
+
+ len = strlen (filename);
+ if (len < 3)
+ return FALSE;
+
+ return g_ascii_strcasecmp (filename + len - 3, ".xz") == 0;
+}
+
static void
backup (const gchar *filename,
GCancellable *cancellable)
{
gchar *command;
gchar *quotedfname;
+ gboolean use_xz;
g_return_if_fail (filename && *filename);
- quotedfname = g_shell_quote (filename);
if (g_cancellable_is_cancelled (cancellable))
return;
@@ -306,15 +321,15 @@ backup (const gchar *filename,
txt = _("Backing Evolution data (Mails, Contacts, Calendar, Tasks, Memos)");
- /* FIXME stay on this file system ,other options?" */
- /* FIXME compression type?" */
- /* FIXME date/time stamp?" */
- /* FIXME backup location?" */
+ quotedfname = g_shell_quote (filename);
+ use_xz = get_filename_is_xz (filename);
+
command = g_strdup_printf (
"cd $HOME && tar chf - $STRIPDATADIR "
"$STRIPCONFIGDIR " EVOLUTION_DIR_FILE " | "
- "gzip > %s", quotedfname);
+ "%s > %s", use_xz ? "xz -z" : "gzip", quotedfname);
run_cmd (command);
+
g_free (command);
g_free (quotedfname);
@@ -502,10 +517,16 @@ restore (const gchar *filename,
gchar *data_dir = NULL;
gchar *config_dir = NULL;
gchar *restored_version = NULL;
+ const gchar *tar_opts;
+
+ if (get_filename_is_xz (filename))
+ tar_opts = "-xJf";
+ else
+ tar_opts = "-xzf";
command = g_strdup_printf (
- "cd $TMP && tar xzf %s "
- EVOLUTION_DIR_FILE, quotedfname);
+ "cd $TMP && tar %s %s " EVOLUTION_DIR_FILE,
+ tar_opts, quotedfname);
run_cmd (command);
g_free (command);
@@ -538,14 +559,14 @@ restore (const gchar *filename,
g_mkdir_with_parents (e_get_user_config_dir (), 0700);
command = g_strdup_printf (
- "cd $DATADIR && tar --strip-components %d -xzf %s %s",
- get_dir_level (data_dir), quotedfname, data_dir);
+ "cd $DATADIR && tar --strip-components %d %s %s %s",
+ get_dir_level (data_dir), tar_opts, quotedfname, data_dir);
run_cmd (command);
g_free (command);
command = g_strdup_printf (
- "cd $CONFIGDIR && tar --strip-components %d -xzf %s %s",
- get_dir_level (config_dir), quotedfname, config_dir);
+ "cd $CONFIGDIR && tar --strip-components %d %s %s %s",
+ get_dir_level (config_dir), tar_opts, quotedfname, config_dir);
run_cmd (command);
g_free (command);
@@ -564,10 +585,17 @@ restore (const gchar *filename,
g_free (config_dir);
g_free (restored_version);
} else {
+ const gchar *decr_opts;
+
+ if (get_filename_is_xz (filename))
+ decr_opts = "xz -cd";
+ else
+ decr_opts = "gzip -cd";
+
run_cmd ("mv $HOME/.evolution $HOME/.evolution_old");
command = g_strdup_printf (
- "cd $HOME && gzip -cd %s | tar xf -", quotedfname);
+ "cd $HOME && %s %s | tar xf -", decr_opts, quotedfname);
run_cmd (command);
g_free (command);
}
@@ -692,15 +720,22 @@ check (const gchar *filename,
{
gchar *command;
gchar *quotedfname;
+ const gchar *tar_opts;
gboolean is_new = TRUE;
g_return_val_if_fail (filename && *filename, FALSE);
+
+ if (get_filename_is_xz (filename))
+ tar_opts = "-tJf";
+ else
+ tar_opts = "-tzf";
+
quotedfname = g_shell_quote (filename);
if (is_new_format)
*is_new_format = FALSE;
- command = g_strdup_printf ("tar ztf %s 1>/dev/null", quotedfname);
+ command = g_strdup_printf ("tar %s %s 1>/dev/null", tar_opts, quotedfname);
result = system (command);
g_free (command);
@@ -711,15 +746,15 @@ check (const gchar *filename,
}
command = g_strdup_printf (
- "tar ztf %s | grep -e \"%s$\"",
- quotedfname, EVOLUTION_DIR_FILE);
+ "tar %s %s | grep -e \"%s$\"",
+ tar_opts, quotedfname, EVOLUTION_DIR_FILE);
result = system (command);
g_free (command);
if (result) {
command = g_strdup_printf (
- "tar ztf %s | grep -e \"^\\.evolution/$\"",
- quotedfname);
+ "tar %s %s | grep -e \"^\\.evolution/$\"",
+ tar_opts, quotedfname);
result = system (command);
g_free (command);
is_new = FALSE;
@@ -739,16 +774,16 @@ check (const gchar *filename,
}
command = g_strdup_printf (
- "tar ztf %s | grep -e \"^\\.evolution/%s$\"",
- quotedfname, ANCIENT_GCONF_DUMP_FILE);
+ "tar %s %s | grep -e \"^\\.evolution/%s$\"",
+ tar_opts, quotedfname, ANCIENT_GCONF_DUMP_FILE);
result = system (command);
g_free (command);
if (result != 0) {
/* maybe it's an ancient backup */
command = g_strdup_printf (
- "tar ztf %s | grep -e \"^\\.evolution/%s$\"",
- quotedfname, ANCIENT_GCONF_DUMP_FILE);
+ "tar %s %s | grep -e \"^\\.evolution/%s$\"",
+ tar_opts, quotedfname, ANCIENT_GCONF_DUMP_FILE);
result = system (command);
g_free (command);
}
diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c
index 7b493e4..ddec885 100644
--- a/shell/e-shell-utils.c
+++ b/shell/e-shell-utils.c
@@ -177,6 +177,8 @@ e_shell_run_save_dialog (EShell *shell,
else if (g_ascii_strcasecmp (flt, "*.ics") == 0)
gtk_file_filter_set_name (
filter, _("iCalendar (.ics)"));
+ else
+ gtk_file_filter_set_name (filter, flt);
while (delim) {
delim++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]