diff options
author | Tor Lillqvist <tml@novell.com> | 2005-12-17 19:52:53 +0800 |
---|---|---|
committer | Tor Lillqvist <tml@src.gnome.org> | 2005-12-17 19:52:53 +0800 |
commit | f6734b1d17682ed7b6cfc046d3cad45e6a28c951 (patch) | |
tree | 8730f2277af197288e7bd4a475be7a6167c50976 /addressbook/gui | |
parent | 22e9edd52a0e6ca23edc14e3ef24fba4da8dc13a (diff) | |
download | gsoc2013-evolution-f6734b1d17682ed7b6cfc046d3cad45e6a28c951.tar.gz gsoc2013-evolution-f6734b1d17682ed7b6cfc046d3cad45e6a28c951.tar.zst gsoc2013-evolution-f6734b1d17682ed7b6cfc046d3cad45e6a28c951.zip |
Use gstdio wrappers. Use GDir API instead of dirent. Use GLib API to
2005-12-17 Tor Lillqvist <tml@novell.com>
* gui/component/addressbook-migrate.c: Use gstdio wrappers. Use
GDir API instead of dirent. Use GLib API to convert file names to
URIs and back. Open files in binary mode.
svn path=/trunk/; revision=30797
Diffstat (limited to 'addressbook/gui')
-rw-r--r-- | addressbook/gui/component/addressbook-migrate.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/addressbook/gui/component/addressbook-migrate.c b/addressbook/gui/component/addressbook-migrate.c index ea5c92a263..42bfbb051f 100644 --- a/addressbook/gui/component/addressbook-migrate.c +++ b/addressbook/gui/component/addressbook-migrate.c @@ -24,11 +24,11 @@ #endif #include <glib.h> +#include <glib/gstdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> -#include <dirent.h> #include <fcntl.h> #include <errno.h> @@ -36,14 +36,16 @@ #include <libebook/e-destination.h> #include <libebook/e-book.h> #include <libgnome/gnome-i18n.h> -#include <e-util/e-util.h> -#include <e-util/e-xml-utils.h> #include <gtk/gtkwidget.h> #include <gtk/gtkvbox.h> #include <gtk/gtkmain.h> #include <gtk/gtklabel.h> #include <gtk/gtkprogressbar.h> -#include <e-util/e-folder-map.h> + +#include "e-util/e-util.h" +#include "e-util/e-util-private.h" +#include "e-util/e-xml-utils.h" +#include "e-util/e-folder-map.h" /*#define SLOW_MIGRATION*/ @@ -174,7 +176,11 @@ check_for_conflict (ESourceGroup *group, char *name) static char * get_source_name (ESourceGroup *group, const char *path) { +#ifndef G_OS_WIN32 char **p = g_strsplit (path, "/", 0); +#else + char **p = g_strsplit_set (path, "\\/", 0); +#endif int i, j, starting_index; int num_elements; gboolean conflict; @@ -390,7 +396,7 @@ migrate_contacts (MigrationContext *context, EBook *old_book, EBook *new_book) static void migrate_contact_folder_to_source (MigrationContext *context, char *old_path, ESource *new_source) { - char *old_uri = g_strdup_printf ("file://%s", old_path); + char *old_uri = g_filename_to_uri (old_path, NULL, NULL); GError *e = NULL; EBook *old_book = NULL, *new_book = NULL; @@ -466,7 +472,7 @@ create_groups (MigrationContext *context, "addressbook", "local", NULL); - base_uri_proto = g_strconcat ("file://", base_uri, NULL); + base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); groups = e_source_list_peek_groups (context->source_list); if (groups) { @@ -785,9 +791,13 @@ migrate_completion_folders (MigrationContext *context) for the uri. */ if (!strncmp (physical_uri, "file://", 7)) { - char *uid = g_hash_table_lookup (context->folder_uid_map, - physical_uri + 7); + char *filename = g_filename_from_uri (physical_uri, NULL, NULL); + char *uid = NULL; + if (filename) + uid = g_hash_table_lookup (context->folder_uid_map, + filename); + g_free (filename); if (uid) source = e_source_list_peek_source_by_uid (context->source_list, uid); } @@ -1000,34 +1010,34 @@ migrate_company_phone_for_local_folders (MigrationContext *context, ESourceGroup static void migrate_pilot_data (const char *old_path, const char *new_path) { - struct dirent *dent; + const char *dent; const char *ext; char *filename; - DIR *dir; + GDir *dir; - if (!(dir = opendir (old_path))) + if (!(dir = g_dir_open (old_path, 0, NULL))) return; - while ((dent = readdir (dir))) { - if ((!strncmp (dent->d_name, "pilot-map-", 10) && - ((ext = strrchr (dent->d_name, '.')) && !strcmp (ext, ".xml"))) || - (!strncmp (dent->d_name, "pilot-sync-evolution-addressbook-", 33) && - ((ext = strrchr (dent->d_name, '.')) && !strcmp (ext, ".db")))) { + while ((dent = g_dir_read_name (dir))) { + if ((!strncmp (dent, "pilot-map-", 10) && + ((ext = strrchr (dent, '.')) && !strcmp (ext, ".xml"))) || + (!strncmp (dent, "pilot-sync-evolution-addressbook-", 33) && + ((ext = strrchr (dent, '.')) && !strcmp (ext, ".db")))) { /* src and dest file formats are identical for both map and changelog files */ 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) { + filename = g_build_filename (old_path, dent, NULL); + if ((fd0 = g_open (filename, O_RDONLY | O_BINARY, 0)) == -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) { + filename = g_build_filename (new_path, dent, NULL); + if ((fd1 = g_open (filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)) == -1) { g_free (filename); close (fd0); continue; @@ -1058,10 +1068,10 @@ migrate_pilot_data (const char *old_path, const char *new_path) if (n != -1) n = fsync (fd1); - + if (n == -1) { - g_warning ("Failed to migrate %s: %s", dent->d_name, strerror (errno)); - unlink (filename); + g_warning ("Failed to migrate %s: %s", dent, strerror (errno)); + g_unlink (filename); } close (fd0); @@ -1070,7 +1080,7 @@ migrate_pilot_data (const char *old_path, const char *new_path) } } - closedir (dir); + g_dir_close (dir); } static MigrationContext* |