Re: [evolution-patches] delete old data patch



On Thu, 2004-07-22 at 11:51 +0800, Not Zed wrote:
> On Fri, 2004-07-16 at 01:56 -0400, JP Rosevear wrote: 
> > On Thu, 2004-07-15 at 15:02 +0800, Not Zed wrote:
> > > Hmm, missed the attach button by >that much<.
> > > 
> > > 
> > > jpr asked me about this, dunno if there's a bug for it.
> > > 
> > > what it does:
> > > 
> > > if you (successfully?) upgraded from a version which stored data in
> > > ~/evolution, it will ask you if you want to delete it.
> > > 
> > > you can choose to not delete it, cancelling the operation - you will
> > > be re-asked again, next time you start evolution, and each time you
> > > start evolution until you either keep or delete it.
> > 
> > Looks pretty good, the only thing that I think would be better was if
> > the cancel button was labelled differently, something like "Remind me
> > later" or something, "Cancel" seems somewhat unclear.

I consulted with Anna and changed Cancel to Remind Me Later and Keep to
Keep Data based on her recommendations.  Tiny change to your patch
attached to set those labels.

-JP
-- 
JP Rosevear <jpr novell com>
Novell, Inc.
? Evolution-Addressbook-SelectNames-common.c
? Evolution-Addressbook-SelectNames-skels.c
? Evolution-Addressbook-SelectNames-stubs.c
? Evolution-Addressbook-SelectNames.h
? upgrade-delete.patch
? glade/Makefile
? glade/Makefile.in
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/shell/ChangeLog,v
retrieving revision 1.1463
diff -u -r1.1463 ChangeLog
--- ChangeLog	26 Jul 2004 06:52:00 -0000	1.1463
+++ ChangeLog	29 Jul 2004 19:00:50 -0000
@@ -1,3 +1,25 @@
+2004-07-29  Not Zed  <NotZed Ximian com>
+ 
+ 	* apps_evolution_shell.schemas.in.in: added last_version item.
+ 
+ 	* shell-errors.xml: added upgrade-remove-1-4 and
+ 	upgrade-remove-1-4-confirm dialogues.
+ 
+ 	* e-shell.c (remove_dir): utility to recursively delete a tree of
+	files and folders.
+ 	(e_shell_attempt_upgrade): keep track of the last upgraded
+ 	version, if != current version, and < 1.5, and it exists, offer to
+ 	remove ~/evolution.  Confirm the offer before actually doing it.
+ 
+ 	* e-shell-window-commands.c: include gnome-about.
+ 	(command_help_faq): fix comment structure
+ 
+ 	* e-shell.c (attempt_upgrade): moved most of this into
+ 	e_shell_attempt_upgrade.
+ 	(e_shell_attempt_upgrade): moved most of this into
+	attempt_upgrade, removed rev args.  It makes sense, really!
+ 	(e_shell_construct): call e_shell_attempt_upgrade instead.
+
 2004-07-22  Not Zed  <NotZed Ximian com>
 
 	* e-shell.c (create_window): merged this into
Index: apps_evolution_shell.schemas.in.in
===================================================================
RCS file: /cvs/gnome/evolution/shell/apps_evolution_shell.schemas.in.in,v
retrieving revision 1.4
diff -u -r1.4 apps_evolution_shell.schemas.in.in
--- apps_evolution_shell.schemas.in.in	9 Jul 2004 11:18:16 -0000	1.4
+++ apps_evolution_shell.schemas.in.in	29 Jul 2004 19:00:51 -0000
@@ -13,6 +13,18 @@
       </locale>
     </schema>
 
+    <!-- last upgraded-from version, if still present -->
+
+    <schema>
+      <key>/schemas/apps/evolution/last_version</key>
+      <applyto>/apps/evolution/last_version</applyto>
+      <owner>evolution</owner>
+      <type>string</type>
+      <locale name="C">
+        <short>Last upgraded Evolution configuration version</short>
+      </locale>
+    </schema>
+
     <!-- Development warning dialog -->
 
     <schema>
Index: e-shell-window-commands.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell-window-commands.c,v
retrieving revision 1.20
diff -u -r1.20 e-shell-window-commands.c
--- e-shell-window-commands.c	6 Jun 2004 22:31:34 -0000	1.20
+++ e-shell-window-commands.c	29 Jul 2004 19:00:53 -0000
@@ -40,6 +40,7 @@
 #include <libgnome/gnome-exec.h>
 #include <libgnome/gnome-url.h>
 #include <libgnome/gnome-i18n.h>
+#include <libgnomeui/gnome-about.h>
 
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
 #include <libgnomevfs/gnome-vfs-mime-utils.h>
@@ -357,7 +358,7 @@
 		  EShellWindow *window,
 		  const char *path)
 {
-	/* FIXME Show when we have a faq
+	/* FIXME Show when we have a faq */
 	/* FIXME use the error */
 	gnome_url_show ("http://gnome.org/projects/evolution/faq.shtml";, NULL);	
 }
Index: e-shell.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell.c,v
retrieving revision 1.251
diff -u -r1.251 e-shell.c
--- e-shell.c	26 Jul 2004 06:52:00 -0000	1.251
+++ e-shell.c	29 Jul 2004 19:00:57 -0000
@@ -24,6 +24,9 @@
 #include <config.h>
 #endif
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "e-shell.h"
 
 #include "e-util/e-dialog-utils.h"
@@ -541,44 +544,54 @@
 	g_free (evolution_dir);
 }
 
-static void
-attempt_upgrade (EShell *shell)
+/* calls components to perform upgrade */
+static gboolean
+attempt_upgrade (EShell *shell, int major, int minor, int revision)
 {
-	GConfClient *gconf_client;
-	int major = 0, minor = 0, revision = 0;
-	char *version_string;
+	GSList *component_infos, *p;
+	gboolean success;
+	int res;
 
-	gconf_client = gconf_client_get_default ();
+	success = TRUE;
 
-	detect_version (gconf_client, &major, &minor, &revision);
+	component_infos = e_component_registry_peek_list (shell->priv->component_registry);
+	for (p = component_infos; success && p != NULL; p = p->next) {
+		const EComponentInfo *info = p->data;
+		CORBA_Environment ev;
 
-	/* if upgrading from < 1.5, we need to copy most data from ~/evolution to ~/.evolution */
-	if (major == 1 && minor < 5) {
-		char *path;
-		long size, space;
+		CORBA_exception_init (&ev);
+		
+		GNOME_Evolution_Component_upgradeFromVersion (info->iface, major, minor, revision, &ev);
+		
+		if (BONOBO_EX (&ev)) {
+			char *exception_text;
+			CORBA_char *id = CORBA_exception_id(&ev);
 
-		path = g_build_filename(g_get_home_dir(), "evolution", NULL);
-		size = e_fsutils_usage(path);
-		g_free(path);
-		space = e_fsutils_avail(g_get_home_dir());
-		if (size != -1 && space != -1 && space < size) {
-			char *required = g_strdup_printf(_("%ld KB"), size);
-			char *have = g_strdup_printf(_("%ld KB"), space);
+			if (strcmp (id, ex_CORBA_NO_IMPLEMENT) == 0) {
+				/* Ignore components that do not implement this version, it
+				   might just mean that they don't need an upgrade path. */
+			} else if (strcmp (id,  ex_GNOME_Evolution_Component_UpgradeFailed) == 0) {
+				GNOME_Evolution_Component_UpgradeFailed *ex = CORBA_exception_value(&ev);
 
-			e_error_run(NULL, "shell:upgrade-nospace", required, have, NULL);
-			g_free(required);
-			g_free(have);
-			_exit(0);
+				res = e_error_run(NULL, "shell:upgrade-failed", ex->what, ex->why, NULL);
+				if (res == GTK_RESPONSE_CANCEL)
+					success = FALSE;
+			} else if (strcmp (id,  ex_GNOME_Evolution_Component_UnsupportedVersion) == 0) {
+				/* This is non-fatal */
+				/* DO WE CARE??? */
+				printf("Upgrade of component failed, unsupported prior version\n");
+			} else {
+				exception_text = bonobo_exception_get_text (&ev);
+				res = e_error_run(NULL, "shell:upgrade-failed", exception_text, _("Uknown system error."), NULL);
+				g_free (exception_text);
+				if (res == GTK_RESPONSE_CANCEL)
+					success = FALSE;
+			}
 		}
+		CORBA_exception_free (&ev);
 	}
 
-	if (!e_shell_attempt_upgrade (shell, major, minor, revision))
-		_exit(0);
-
-	version_string = g_strdup_printf ("%s.%s", BASE_VERSION, UPGRADE_REVISION);
-	gconf_client_set_string (gconf_client, "/apps/evolution/version", version_string, NULL);
-	g_object_unref (gconf_client);
-	g_free (version_string);
+	return success;
 }
 
 /**
@@ -624,7 +637,7 @@
 	/* activate all the components (peek list does this implictly) */
 	component = e_component_registry_peek_list (shell->priv->component_registry);
 	
-	attempt_upgrade(shell);
+	e_shell_attempt_upgrade(shell);
 
 	if (e_shell_startup_wizard_create () == FALSE) {
 		bonobo_object_unref (BONOBO_OBJECT (shell));
@@ -688,78 +701,161 @@
 	return new;
 }
 
+static int
+remove_dir(const char *root, const char *path)
+{
+	DIR *dir;
+	struct dirent *d;
+	int res = -1;
+	char *new = NULL;
+	struct stat st;
+
+	dir = opendir(path);
+	if (dir == NULL)
+		return -1;
+
+	while ( (d = readdir(dir)) ) {
+		if (!strcmp(d->d_name, ".")
+		    || !strcmp(d->d_name, ".."))
+			continue;
+
+		new = g_build_filename(path, d->d_name, NULL);
+		if (stat(new, &st) == -1)
+			goto fail;
+
+		/* make sure we're really removing something from evolution dir */
+		g_assert(strlen(path) >= strlen(root)
+			 && strncmp(root, path, strlen(root)) == 0);
+
+		if (S_ISDIR(st.st_mode)) {
+			if (remove_dir(root, new) == -1)
+				goto fail;
+		} else {
+			if (unlink(new) == -1)
+				goto fail;
+		}
+		g_free(new);
+		new = NULL;
+	}
+
+	res = rmdir(path);
+fail:
+	g_free(new);
+	closedir(dir);
+	return res;
+}
+
 /**
  * e_shell_attempt_upgrade:
  * @shell: 
- * @from_version: 
  * 
- * Upgrade config and components from the specified version name.
+ * Upgrade config and components from the currently installed version.
  * 
- * Return value: %TRUE If it works, %FALSE if it fails (it should only fail if
- * upgrade from @from_version is unsupported).
+ * Return value: %TRUE If it works.  If it fails the application will exit.
  **/
 gboolean
-e_shell_attempt_upgrade (EShell *shell, int major, int minor, int revision)
+e_shell_attempt_upgrade (EShell *shell)
 {
-	GSList *component_infos, *p;
-	int current_major, current_minor, current_revision;
-	gboolean success;
-	int res;
+	GConfClient *gconf_client;
+	int major = 0, minor = 0, revision = 0;
+	int lmajor, lminor, lrevision;
+	int cmajor, cminor, crevision;
+	char *version_string, *last_version = NULL;
+	int done_upgrade = FALSE;
+	char *oldpath;
+	struct stat st;
 
-	g_return_val_if_fail (E_IS_SHELL (shell), FALSE);
+	gconf_client = gconf_client_get_default();
 
-	sscanf (BASE_VERSION, "%u.%u", &current_major, &current_minor);
+	oldpath = g_build_filename(g_get_home_dir(), "evolution", NULL);
 
-	current_revision = atoi (UPGRADE_REVISION);
+	g_assert(sscanf(BASE_VERSION, "%u.%u", &cmajor, &cminor) == 2);
+	crevision = atoi(UPGRADE_REVISION);
 
-	if (! (current_major > major
-	       || (current_major == major && current_minor > minor)
-	       || (current_minor == current_minor && current_revision > revision))) {
-		return TRUE;
-	}
+	detect_version (gconf_client, &major, &minor, &revision);
 
-	success = TRUE;
+	if (!(cmajor > major
+	      || (cmajor == major && cminor > minor)
+	      || (cminor == minor && crevision > revision)))
+		goto check_old;
 
-	component_infos = e_component_registry_peek_list (shell->priv->component_registry);
-	for (p = component_infos; success && p != NULL; p = p->next) {
-		const EComponentInfo *info = p->data;
-		CORBA_Environment ev;
+	/* if upgrading from < 1.5, we need to copy most data from ~/evolution to ~/.evolution */
+	if (major == 1 && minor < 5) {
+		long size, space;
 
-		CORBA_exception_init (&ev);
-		
-		GNOME_Evolution_Component_upgradeFromVersion (info->iface, major, minor, revision, &ev);
-		
-		if (BONOBO_EX (&ev)) {
-			char *exception_text;
-			CORBA_char *id = CORBA_exception_id(&ev);
+		size = e_fsutils_usage(oldpath);
+		space = e_fsutils_avail(g_get_home_dir());
+		if (size != -1 && space != -1 && space < size) {
+			char *required = g_strdup_printf(_("%ld KB"), size);
+			char *have = g_strdup_printf(_("%ld KB"), space);
 
-			if (strcmp (id, ex_CORBA_NO_IMPLEMENT) == 0) {
-				/* Ignore components that do not implement this version, it
-				   might just mean that they don't need an upgrade path. */
-			} else if (strcmp (id,  ex_GNOME_Evolution_Component_UpgradeFailed) == 0) {
-				GNOME_Evolution_Component_UpgradeFailed *ex = CORBA_exception_value(&ev);
+			e_error_run(NULL, "shell:upgrade-nospace", required, have, NULL);
+			g_free(required);
+			g_free(have);
+			_exit(0);
+		}
+	}
 
-				res = e_error_run(NULL, "shell:upgrade-failed", ex->what, ex->why, NULL);
-				if (res == GTK_RESPONSE_CANCEL)
-					success = FALSE;
-			} else if (strcmp (id,  ex_GNOME_Evolution_Component_UnsupportedVersion) == 0) {
-				/* This is non-fatal */
-				/* DO WE CARE??? */
-				printf("Upgrade of component failed, unsupported prior version\n");
-			} else {
-				exception_text = bonobo_exception_get_text (&ev);
-				res = e_error_run(NULL, "shell:upgrade-failed", exception_text, _("Uknown system error."), NULL);
-				g_free (exception_text);
-				if (res == GTK_RESPONSE_CANCEL)
-					success = FALSE;
-			}
+	if (!attempt_upgrade (shell, major, minor, revision))
+		_exit(0);
+
+	/* mark as upgraded */
+	version_string = g_strdup_printf ("%s.%s", BASE_VERSION, UPGRADE_REVISION);
+	gconf_client_set_string (gconf_client, "/apps/evolution/version", version_string, NULL);
+	done_upgrade = TRUE;
+
+check_old:
+	/* if the last upgraded version was old, check for stuff to remove */
+	if (done_upgrade
+	    || 	(last_version = gconf_client_get_string (gconf_client, "/apps/evolution/last_version", NULL)) == NULL
+	    ||  sscanf(last_version, "%d.%d.%d", &lmajor, &lminor, &lrevision) != 3) {
+		lmajor = major;
+		lminor = minor;
+		lrevision = revision;
+	}
+	g_free(last_version);
+
+	if (lmajor == 1 && lminor < 5
+	    && stat(oldpath, &st) == 0
+	    && S_ISDIR(st.st_mode)) {
+		int res;
+
+		last_version = g_strdup_printf("%u.%u.%u", lmajor, lminor, lrevision);
+		res = e_error_run(NULL, "shell:upgrade-remove-1-4", last_version, NULL);
+		g_free(last_version);
+
+		switch (res) {
+		case GTK_RESPONSE_OK: /* 'delete' */
+			if (e_error_run(NULL, "shell:upgrade-remove-1-4-confirm", NULL) == GTK_RESPONSE_OK)
+				remove_dir(oldpath, oldpath);
+			else
+				break;
+			/* falls through */
+		case GTK_RESPONSE_ACCEPT: /* 'keep' */
+			lmajor = cmajor;
+			lminor = cminor;
+			lrevision = crevision;
+			break;
+		default:
+			/* cancel - noop */
+			break;
 		}
-		CORBA_exception_free (&ev);
+	} else {
+		/* otherwise 'last version' is now the same as current */
+		lmajor = cmajor;
+		lminor = cminor;
+		lrevision = crevision;
 	}
 
-	return success;
-}
+	last_version = g_strdup_printf("%u.%u.%u", lmajor, lminor, lrevision);
+	gconf_client_set_string (gconf_client, "/apps/evolution/last_version", last_version, NULL);
+	g_free(last_version);
+
+	g_free(oldpath);
+	g_object_unref (gconf_client);
 
+	return TRUE;
+}
 
 /**
  * e_shell_create_window:
Index: e-shell.h
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell.h,v
retrieving revision 1.67
diff -u -r1.67 e-shell.h
--- e-shell.h	9 Apr 2004 15:46:00 -0000	1.67
+++ e-shell.h	29 Jul 2004 19:00:57 -0000
@@ -99,10 +99,7 @@
 EShell                *e_shell_new        (EShellStartupLineMode  startup_line_mode,
 					   EShellConstructResult *construct_result_return);
 
-gboolean  e_shell_attempt_upgrade  (EShell     *shell,
-				    int major,
-				    int minor,
-				    int revision);
+gboolean  e_shell_attempt_upgrade  (EShell     *shell);
 
 EShellWindow *e_shell_create_window         (EShell       *shell,
 					     const char   *component_id,
Index: shell-errors.xml
===================================================================
RCS file: /cvs/gnome/evolution/shell/shell-errors.xml,v
retrieving revision 1.4
diff -u -r1.4 shell-errors.xml
--- shell-errors.xml	26 May 2004 21:52:10 -0000	1.4
+++ shell-errors.xml	29 Jul 2004 19:00:58 -0000
@@ -20,6 +20,31 @@
   <button stock="gtk-ok" label="Continue" response="GTK_RESPONSE_OK"/>
  </error>
 
+ <error id="upgrade-remove-1-4" type="question" default="GTK_RESPONSE_CANCEL">
+  <title>Delete old data from version {0}?</title>
+  <primary>Delete old data from version {0}?</primary>
+  <secondary>The previous version of evolution stored its data in a different location.
+
+If you choose to remove this data, the entire contents of the &quot;evolution&quot; directory will be removed permanently.  If you choose to keep this data, then you may manually remove the contents of &quot;evolution&quot; at your convenience.
+</secondary>
+  <button label="_Remind Me Later" response="GTK_RESPONSE_CANCEL"/>
+  <button label="_Keep Data" response="GTK_RESPONSE_ACCEPT"/>
+  <button stock="gtk-delete" response="GTK_RESPONSE_OK"/>
+ </error>
+
+ <error id="upgrade-remove-1-4-confirm" type="warning" default="GTK_RESPONSE_CANCEL">
+  <title>Really delete old data?</title>
+  <primary>Really delete old data?</primary>
+  <secondary>The entire contents of the &quot;evolution&quot; directory is about to be be permanently removed.
+
+It is suggested you manually verify that all of your mail, contact, and calendar data is present, and that this version of Evolution operates correctly before deleting this old data.
+
+Once deleted, you cannot downgrade to the previous version of Evolution without manual intervention.
+</secondary>
+  <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/>
+  <button stock="gtk-delete" response="GTK_RESPONSE_OK"/>
+ </error>
+
  <error id="noshell" type="error">
   <title>Cannot start Evolution</title>
   <primary>Evolution can not start.</primary>
Index: shell-errors.xml.h
===================================================================
RCS file: /cvs/gnome/evolution/shell/shell-errors.xml.h,v
retrieving revision 1.5
diff -u -r1.5 shell-errors.xml.h
--- shell-errors.xml.h	6 Jul 2004 21:33:46 -0000	1.5
+++ shell-errors.xml.h	29 Jul 2004 19:00:58 -0000
@@ -13,6 +13,27 @@
 	"If you choose to continue, you may not have access to some of your old data.\n"
 	"");
 char *s = N_("Continue");
+/* shell:upgrade-remove-1-4 title */
+char *s = N_("Delete old data from version {0}?");
+/* shell:upgrade-remove-1-4 primary */
+char *s = N_("Delete old data from version {0}?");
+/* shell:upgrade-remove-1-4 secondary */
+char *s = N_("The previous version of evolution stored its data in a different location.\n"
+	"\n"
+	"If you choose to remove this data, the entire contents of the \"evolution\" directory will be removed permanently.  If you choose to keep this data, then you may manually remove the contents of \"evolution\" at your convenience.\n"
+	"");
+char *s = N_("Keep");
+/* shell:upgrade-remove-1-4-confirm title */
+char *s = N_("Really delete old data?");
+/* shell:upgrade-remove-1-4-confirm primary */
+char *s = N_("Really delete old data?");
+/* shell:upgrade-remove-1-4-confirm secondary */
+char *s = N_("The entire contents of the \"evolution\" directory is about to be be permanently removed.\n"
+	"\n"
+	"It is suggested you manually verify that all of your mail, contact, and calendar data is present, and that this version of Evolution operates correctly before deleting this old data.\n"
+	"\n"
+	"Once deleted, you cannot downgrade to the previous version of Evolution without manual intervention.\n"
+	"");
 /* shell:noshell title */
 char *s = N_("Cannot start Evolution");
 /* shell:noshell primary */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]