aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-04-27 05:36:34 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-04-27 05:36:34 +0800
commit3e5f3c254e68d2811bb6baedcbe45cb658b0e043 (patch)
tree37d65c25f770c5ce30cd0b80e06b1a6eb3c9cc6d
parent9fe61b12b4147568c15e2a3649f5a30d8c7bdab1 (diff)
downloadgsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.tar
gsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.tar.gz
gsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.tar.bz2
gsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.tar.lz
gsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.tar.xz
gsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.tar.zst
gsoc2013-evolution-3e5f3c254e68d2811bb6baedcbe45cb658b0e043.zip
New function to migrate pilot data. (migrate_calendars): Migrate pilot
2004-04-26 Jeffrey Stedfast <fejj@ximian.com> * gui/migration.c (migrate_pilot_data): New function to migrate pilot data. (migrate_calendars): Migrate pilot data if upgrade version <=1.5.9 (migrate_tasks): Same. svn path=/trunk/; revision=25620
-rw-r--r--calendar/ChangeLog7
-rw-r--r--calendar/gui/migration.c151
2 files changed, 152 insertions, 6 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 7b5897aa26..df30826223 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,10 @@
+2004-04-26 Jeffrey Stedfast <fejj@ximian.com>
+
+ * gui/migration.c (migrate_pilot_data): New function to migrate
+ pilot data.
+ (migrate_calendars): Migrate pilot data if upgrade version <=1.5.9
+ (migrate_tasks): Same.
+
2004-04-23 Rodney Dawes <dobey@ximian.com>
* gui/alarm-notify/notify-main.c (main): Call e_icon_factory_init ()
diff --git a/calendar/gui/migration.c b/calendar/gui/migration.c
index 18300210cf..e039a69215 100644
--- a/calendar/gui/migration.c
+++ b/calendar/gui/migration.c
@@ -21,6 +21,13 @@
*/
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <errno.h>
+
#include <bonobo/bonobo-i18n.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-xfer.h>
@@ -33,6 +40,8 @@
#include <libecal/e-cal.h>
#include <e-util/e-bconf-map.h>
#include <e-util/e-folder-map.h>
+#include <libedataserver/e-dbhash.h>
+#include <libedataserver/e-xml-hash-utils.h>
#include "calendar-config-keys.h"
#include "migration.h"
@@ -482,8 +491,7 @@ create_task_sources (TasksComponent *component,
*personal_source = NULL;
base_uri = g_build_filename (tasks_component_peek_base_directory (component),
- "/tasks/local/",
- NULL);
+ "tasks", "local", NULL);
base_uri_proto = g_strconcat ("file://", base_uri, NULL);
@@ -543,6 +551,116 @@ create_task_sources (TasksComponent *component,
g_free (base_uri);
}
+static void
+migrate_pilot_db_key (const char *key, const char *data, gpointer user_data)
+{
+ EXmlHash *xmlhash = user_data;
+
+ e_xmlhash_add (xmlhash, key, data);
+}
+
+static void
+migrate_pilot_data (const char *old_path, const char *new_path)
+{
+ struct dirent *dent;
+ const char *ext;
+ char *filename;
+ DIR *dir;
+
+ if (!(dir = opendir (old_path)))
+ return;
+
+ while ((dent = readdir (dir))) {
+ if (!strncmp (dent->d_name, "pilot-map-todo-", 15) &&
+ ((ext = strrchr (dent->d_name, '.')) && !strcmp (ext, ".xml"))) {
+ /* pilot map file - src and dest file formats are identical */
+ unsigned char inbuf[4096];
+ size_t nread, nwritten;
+ int fd0, fd1;
+ ssize_t n;
+
+ filename = g_build_filename (old_path, dent->d_name, NULL);
+ if ((fd0 = open (filename, O_RDONLY)) == -1) {
+ g_free (filename);
+ continue;
+ }
+
+ g_free (filename);
+ filename = g_build_filename (new_path, dent->d_name, NULL);
+ if ((fd1 = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) {
+ g_free (filename);
+ close (fd0);
+ continue;
+ }
+
+ do {
+ do {
+ n = read (fd0, inbuf, sizeof (inbuf));
+ } while (n == -1 && errno == EINTR);
+
+ if (n < 1)
+ break;
+
+ nread = n;
+ nwritten = 0;
+ do {
+ do {
+ n = write (fd1, inbuf + nwritten, nread - nwritten);
+ } while (n == -1 && errno == EINTR);
+
+ if (n > 0)
+ nwritten += n;
+ } while (nwritten < nread && n != -1);
+
+ if (n == -1)
+ break;
+ } while (1);
+
+ if (n != -1)
+ n = fsync (fd1);
+
+ if (n == -1) {
+ g_warning ("Failed to migrate %s: %s", dent->d_name, strerror (errno));
+ unlink (filename);
+ }
+
+ close (fd0);
+ close (fd1);
+ g_free (filename);
+ } else if (strstr (dent->d_name, ".ics-pilot-sync-evolution-todo-") &&
+ ((ext = strrchr (dent->d_name, '.')) && !strcmp (ext, ".db"))) {
+ /* src and dest formats differ, src format is db3 while dest format is xml */
+ EXmlHash *xmlhash;
+ EDbHash *dbhash;
+ struct stat st;
+
+ filename = g_build_filename (old_path, dent->d_name, NULL);
+ if (stat (filename, &st) == -1) {
+ g_free (filename);
+ continue;
+ }
+
+ dbhash = e_dbhash_new (filename);
+ g_free (filename);
+
+ filename = g_build_filename (new_path, dent->d_name, NULL);
+ if (stat (filename, &st) != -1)
+ unlink (filename);
+ xmlhash = e_xmlhash_new (filename);
+ g_free (filename);
+
+ e_dbhash_foreach_key (dbhash, migrate_pilot_db_key, xmlhash);
+
+ e_dbhash_destroy (dbhash);
+
+ e_xmlhash_write (xmlhash);
+ e_xmlhash_destroy (xmlhash);
+ }
+ }
+
+ closedir (dir);
+}
+
gboolean
migrate_calendars (CalendarComponent *component, int major, int minor, int revision)
{
@@ -642,7 +760,17 @@ migrate_calendars (CalendarComponent *component, int major, int minor, int revis
g_object_unref (gconf);
}
-
+
+ if (minor <= 5 && revision <= 9) {
+ char *old_path, *new_path;
+
+ old_path = g_build_filename (g_get_home_dir (), "evolution", "local", "Calendar", NULL);
+ new_path = g_build_filename (calendar_component_peek_base_directory (component),
+ "calendar", "local", "system", NULL);
+ migrate_pilot_data (old_path, new_path);
+ g_free (new_path);
+ g_free (old_path);
+ }
}
e_source_list_sync (calendar_component_peek_source_list (component), NULL);
@@ -704,13 +832,13 @@ migrate_tasks (TasksComponent *component, int major, int minor, int revision)
if (minor <= 4) {
GSList *migration_dirs, *l;
char *path, *local_task_folder;
-
+
setup_progress_dialog (TRUE);
path = g_build_filename (g_get_home_dir (), "evolution", "local", NULL);
migration_dirs = e_folder_map_local_folders (path, "tasks");
local_task_folder = g_build_filename (path, "Tasks", NULL);
- g_free (path);
+ g_free (path);
if (personal_source)
migrate_ical_folder_to_source (local_task_folder, personal_source, E_CAL_SOURCE_TYPE_TODO);
@@ -732,7 +860,18 @@ migrate_tasks (TasksComponent *component, int major, int minor, int revision)
g_free (local_task_folder);
dialog_close ();
- }
+ }
+
+ if (minor <= 5 && revision <= 9) {
+ char *old_path, *new_path;
+
+ old_path = g_build_filename (g_get_home_dir (), "evolution", "local", "Tasks", NULL);
+ new_path = g_build_filename (tasks_component_peek_base_directory (component),
+ "tasks", "local", "system", NULL);
+ migrate_pilot_data (old_path, new_path);
+ g_free (new_path);
+ g_free (old_path);
+ }
}
e_source_list_sync (tasks_component_peek_source_list (component), NULL);