From a7943ce5a42ef266579e60ce272c9ee3f547be03 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 8 Aug 2000 03:42:47 +0000 Subject: Only retry another uid if we had a name clash, otherwise fail. 2000-08-07 Not Zed * providers/mh/camel-mh-folder.c (mh_append_message): Only retry another uid if we had a name clash, otherwise fail. 2000-08-04 Not Zed * camel-url.c (camel_url_set_protocol): (camel_url_set_host): (camel_url_set_path): (camel_url_set_port): Url editing functions. 2000-08-02 Not Zed * providers/mh/camel-mh-summary.c (camel_mh_summary_sync): Expunge from the end, so the index isn't messed up when you remove a message. * providers/mh/camel-mh-folder.c (mh_append_message): Fix a bug where it would never open an output file/uid. * providers/mbox/camel-mbox-store.c (rename_folder): Implementation for mbox as well. * camel-store.c (camel_store_rename_folder): New method to rename folders. (rename_folder): Default implementation. * providers/mh/camel-mh-store.c (delete_folder): Implement this. (rename_folder): Implement a rename operation. svn path=/trunk/; revision=4590 --- camel/providers/mbox/camel-mbox-store.c | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'camel/providers/mbox') diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c index 19b7c54612..e3396a7965 100644 --- a/camel/providers/mbox/camel-mbox-store.c +++ b/camel/providers/mbox/camel-mbox-store.c @@ -44,6 +44,7 @@ static CamelFolder *get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex); static void delete_folder (CamelStore *store, const char *folder_name, CamelException *ex); +static void rename_folder(CamelStore *store, const char *old_name, const char *new_name, CamelException *ex); static char *get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); @@ -58,6 +59,7 @@ camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class) camel_store_class->get_folder = get_folder; camel_store_class->delete_folder = delete_folder; + camel_store_class->rename_folder = rename_folder; camel_store_class->get_folder_name = get_folder_name; } @@ -169,8 +171,7 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) struct stat st; int status; - name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path, - folder_name); + name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path, folder_name); if (stat (name, &st) == -1) { if (errno == ENOENT) { /* file doesn't exist - it's kinda like deleting it ;-) */ @@ -220,6 +221,51 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) } } +static int xrename(char *oldp, char *newp, char *prefix, char *suffix, CamelException *ex) +{ + struct stat st; + char *old = g_strconcat(prefix, oldp, suffix, 0); + char *new = g_strconcat(prefix, newp, suffix, 0); + int ret = -1; + + printf("renaming %s%s to %s%s\n", oldp, suffix, newp, suffix); + + /* FIXME: this has races ... */ + if (!(stat(new, &st) == -1 && errno==ENOENT)) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + "Could not rename folder %s to %s: destination exists", + old, new); + } else if (rename(old, new) == 0 || errno==ENOENT) { + ret = 0; + } else if (stat(old, &st) == -1 && errno==ENOENT && stat(new, &st) == 0) { + /* for nfs, check if the rename worked anyway ... */ + ret = 0; + } + printf("success = %d\n", ret); + + g_free(old); + g_free(new); + return ret; +} + +static void rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex) +{ + char *path = CAMEL_SERVICE (store)->url->path; + + /* try to rollback failures, has obvious races */ + if (xrename(old, new, path, ".ibex", ex)) { + return; + } + if (xrename(old, new, path, "-ev-summary", ex)) { + xrename(new, old, path, ".ibex", ex); + return; + } + if (xrename(old, new, path, "", ex)) { + xrename(new, old, path, "-ev-summary", ex); + xrename(new, old, path, ".ibex", ex); + } +} + static char * get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) { -- cgit v1.2.3