From 9e58087307421a11742b41003edda9a7b949bd31 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 5 Feb 2004 08:18:35 +0000 Subject: rename .cmeta file too, and fix the recovery order. 2004-02-05 Not Zed * providers/local/camel-mbox-store.c (rename_folder): rename .cmeta file too, and fix the recovery order. * providers/local/camel-local-store.c (rename_folder): rename the .cmeta file too. * providers/local/camel-local-folder.c (local_rename): fix this to use local_get_full_path stuff. * camel-store.c (camel_store_rename_folder): fix umr's comparing old and new names. svn path=/trunk/; revision=24630 --- camel/ChangeLog | 14 + camel/camel-store.c | 2 +- camel/providers/local/camel-local-folder.c | 27 +- camel/providers/local/camel-local-folder.h | 4 +- camel/providers/local/camel-local-store.c | 8 + camel/providers/local/camel-mbox-store.c | 603 ++++++++++++++--------------- 6 files changed, 342 insertions(+), 316 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index 1e5cda0012..9de19c916f 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,17 @@ +2004-02-05 Not Zed + + * providers/local/camel-mbox-store.c (rename_folder): rename + .cmeta file too, and fix the recovery order. + + * providers/local/camel-local-store.c (rename_folder): rename the + .cmeta file too. + + * providers/local/camel-local-folder.c (local_rename): fix this to + use local_get_full_path stuff. + + * camel-store.c (camel_store_rename_folder): fix umr's comparing + old and new names. + 2004-02-05 Not Zed ** See bug #53553. diff --git a/camel/camel-store.c b/camel/camel-store.c index d4ebdc89b8..10f14a8568 100644 --- a/camel/camel-store.c +++ b/camel/camel-store.c @@ -409,7 +409,7 @@ camel_store_rename_folder (CamelStore *store, const char *old_namein, const char d(printf("store rename folder %s '%s' '%s'\n", ((CamelService *)store)->url->protocol, old_name, new_name)); - if (strcmp(old_name, new_name) == 0) + if (strcmp(old_namein, new_name) == 0) return; /* need to save this, since old_namein might be folder->full_name, which could go away */ diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c index 7bb7d4d40a..ef1bcaf526 100644 --- a/camel/providers/local/camel-local-folder.c +++ b/camel/providers/local/camel-local-folder.c @@ -73,8 +73,8 @@ static int local_setv(CamelObject *object, CamelException *ex, CamelArgV *args); static int local_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex); static void local_unlock(CamelLocalFolder *lf); -static char *local_get_full_path (const char *toplevel_dir, const char *full_name); -static char *local_get_meta_path (const char *toplevel_dir, const char *full_name, const char *ext); +static char *local_get_full_path(const char *toplevel_dir, const char *full_name); +static char *local_get_meta_path(const char *toplevel_dir, const char *full_name, const char *ext); static void local_refresh_info(CamelFolder *folder, CamelException *ex); @@ -242,15 +242,15 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con /* not really sure to do with these for now? */ lf->summary_path = g_strdup_printf("%s.ev-summary", tmp); lf->index_path = g_strdup_printf("%s.ibex", tmp); - statepath = g_strdup_printf ("%s.cmeta", tmp); + statepath = g_strdup_printf("%s.cmeta", tmp); } else { - lf->folder_path = CLOCALF_CLASS (lf)->get_full_path (root_dir_path, full_name); - lf->summary_path = CLOCALF_CLASS (lf)->get_meta_path (root_dir_path, full_name, ".ev-summary"); - lf->index_path = CLOCALF_CLASS (lf)->get_meta_path (root_dir_path, full_name, ".ibex"); - statepath = CLOCALF_CLASS (lf)->get_meta_path (root_dir_path, full_name, ".cmeta"); + lf->folder_path = CLOCALF_CLASS(lf)->get_full_path(root_dir_path, full_name); + lf->summary_path = CLOCALF_CLASS(lf)->get_meta_path(root_dir_path, full_name, ".ev-summary"); + lf->index_path = CLOCALF_CLASS(lf)->get_meta_path(root_dir_path, full_name, ".ibex"); + statepath = CLOCALF_CLASS(lf)->get_meta_path(root_dir_path, full_name, ".cmeta"); } camel_object_set(lf, NULL, CAMEL_OBJECT_STATE_FILE, statepath, NULL); - g_free (statepath); + g_free(statepath); lf->flags = flags; @@ -539,6 +539,7 @@ static void local_rename(CamelFolder *folder, const char *newname) { CamelLocalFolder *lf = (CamelLocalFolder *)folder; + char *statepath; d(printf("renaming local folder paths to '%s'\n", newname)); @@ -547,9 +548,13 @@ local_rename(CamelFolder *folder, const char *newname) g_free(lf->folder_path); g_free(lf->summary_path); g_free(lf->index_path); - lf->folder_path = g_strdup_printf("%s/%s", lf->base_path, newname); - lf->summary_path = g_strdup_printf("%s/%s.ev-summary", lf->base_path, newname); - lf->index_path = g_strdup_printf("%s/%s.ibex", lf->base_path, newname); + + lf->folder_path = CLOCALF_CLASS(lf)->get_full_path(lf->base_path, newname); + lf->summary_path = CLOCALF_CLASS(lf)->get_meta_path(lf->base_path, newname, ".ev-summary"); + lf->index_path = CLOCALF_CLASS(lf)->get_meta_path(lf->base_path, newname, ".ibex"); + statepath = CLOCALF_CLASS(lf)->get_meta_path(lf->base_path, newname, ".cmeta"); + camel_object_set(lf, NULL, CAMEL_OBJECT_STATE_FILE, statepath, NULL); + g_free(statepath); /* FIXME: Poke some internals, sigh */ camel_folder_summary_set_filename(folder->summary, lf->summary_path); diff --git a/camel/providers/local/camel-local-folder.h b/camel/providers/local/camel-local-folder.h index 73059f03b3..00669e738b 100644 --- a/camel/providers/local/camel-local-folder.h +++ b/camel/providers/local/camel-local-folder.h @@ -75,8 +75,8 @@ typedef struct { /* Virtual methods */ /* path construction, only used at init */ - char * (* get_full_path) (const char *toplevel_dir, const char *full_name); - char * (* get_meta_path) (const char *toplevel_dir, const char *full_name, const char *ext); + char * (* get_full_path)(const char *toplevel_dir, const char *full_name); + char * (* get_meta_path)(const char *toplevel_dir, const char *full_name, const char *ext); /* summary factory, only used at init */ CamelLocalSummary *(*create_summary)(const char *path, const char *folder, CamelIndex *index); diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c index a0eaf9d68f..09b644a318 100644 --- a/camel/providers/local/camel-local-store.c +++ b/camel/providers/local/camel-local-store.c @@ -339,6 +339,9 @@ rename_folder(CamelStore *store, const char *old, const char *new, CamelExceptio if (xrename(old, new, path, ".ev-summary", TRUE, ex)) goto summary_failed; + if (xrename(old, new, path, ".cmeta", TRUE, ex)) + goto cmeta_failed; + if (xrename(old, new, path, "", FALSE, ex)) goto base_failed; @@ -350,7 +353,12 @@ rename_folder(CamelStore *store, const char *old, const char *new, CamelExceptio return; + /* The (f)utility of this recovery effort is quesitonable */ + base_failed: + xrename(new, old, path, ".cmeta", TRUE, ex); + +cmeta_failed: xrename(new, old, path, ".ev-summary", TRUE, ex); summary_failed: diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c index 6308c700fe..2567978fa1 100644 --- a/camel/providers/local/camel-mbox-store.c +++ b/camel/providers/local/camel-mbox-store.c @@ -2,7 +2,7 @@ * * Authors: Michael Zucchi * - * Copyright (C) 2000 Ximian, Inc. + * Copyright(C) 2000 Ximian, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -43,25 +43,25 @@ static CamelLocalStoreClass *parent_class = NULL; /* Returns the class for a CamelMboxStore */ -#define CMBOXS_CLASS(so) CAMEL_MBOX_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so)) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so)) -#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so)) +#define CMBOXS_CLASS(so) CAMEL_MBOX_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(so)) +#define CF_CLASS(so) CAMEL_FOLDER_CLASS(CAMEL_OBJECT_GET_CLASS(so)) +#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS(CAMEL_OBJECT_GET_CLASS(so)) -extern char *camel_mbox_folder_get_full_path (const char *toplevel_dir, const char *full_name); -extern char *camel_mbox_folder_get_meta_path (const char *toplevel_dir, const char *full_name, const char *ext); +extern char *camel_mbox_folder_get_full_path(const char *toplevel_dir, const char *full_name); +extern char *camel_mbox_folder_get_meta_path(const char *toplevel_dir, const char *full_name, const char *ext); static CamelFolder *get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex); static void delete_folder(CamelStore *store, const char *folder_name, CamelException *ex); -static void rename_folder (CamelStore *store, const char *old, const char *new, CamelException *ex); -static CamelFolderInfo *create_folder (CamelStore *store, const char *parent_name, const char *folder_name, CamelException *ex); -static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex); +static void rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex); +static CamelFolderInfo *create_folder(CamelStore *store, const char *parent_name, const char *folder_name, CamelException *ex); +static CamelFolderInfo *get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelException *ex); static void -camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class) +camel_mbox_store_class_init(CamelMboxStoreClass *camel_mbox_store_class) { - CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_mbox_store_class); + CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS(camel_mbox_store_class); - parent_class = (CamelLocalStoreClass *)camel_type_get_global_classfuncs(camel_local_store_get_type()); + parent_class =(CamelLocalStoreClass *)camel_type_get_global_classfuncs(camel_local_store_get_type()); /* virtual method overload */ camel_store_class->get_folder = get_folder; @@ -74,37 +74,37 @@ camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class) } CamelType -camel_mbox_store_get_type (void) +camel_mbox_store_get_type(void) { static CamelType camel_mbox_store_type = CAMEL_INVALID_TYPE; if (camel_mbox_store_type == CAMEL_INVALID_TYPE) { - camel_mbox_store_type = camel_type_register (CAMEL_LOCAL_STORE_TYPE, "CamelMboxStore", - sizeof (CamelMboxStore), - sizeof (CamelMboxStoreClass), - (CamelObjectClassInitFunc) camel_mbox_store_class_init, - NULL, - NULL, - NULL); + camel_mbox_store_type = camel_type_register(CAMEL_LOCAL_STORE_TYPE, "CamelMboxStore", + sizeof(CamelMboxStore), + sizeof(CamelMboxStoreClass), + (CamelObjectClassInitFunc) camel_mbox_store_class_init, + NULL, + NULL, + NULL); } return camel_mbox_store_type; } static char * -mbox_folder_name_to_path (CamelStore *store, const char *folder_name) +mbox_folder_name_to_path(CamelStore *store, const char *folder_name) { - const char *toplevel_dir = CAMEL_LOCAL_STORE (store)->toplevel_dir; + const char *toplevel_dir = CAMEL_LOCAL_STORE(store)->toplevel_dir; - return camel_mbox_folder_get_full_path (toplevel_dir, folder_name); + return camel_mbox_folder_get_full_path(toplevel_dir, folder_name); } static char * -mbox_folder_name_to_meta_path (CamelStore *store, const char *folder_name, const char *ext) +mbox_folder_name_to_meta_path(CamelStore *store, const char *folder_name, const char *ext) { - const char *toplevel_dir = CAMEL_LOCAL_STORE (store)->toplevel_dir; + const char *toplevel_dir = CAMEL_LOCAL_STORE(store)->toplevel_dir; - return camel_mbox_folder_get_meta_path (toplevel_dir, folder_name, ext); + return camel_mbox_folder_get_meta_path(toplevel_dir, folder_name, ext); } static char *extensions[] = { @@ -112,91 +112,91 @@ static char *extensions[] = { }; static gboolean -ignore_file (const char *filename, gboolean sbd) +ignore_file(const char *filename, gboolean sbd) { int flen, len, i; - flen = strlen (filename); - for (i = 0; i < (sizeof (extensions) / sizeof (extensions[0])); i++) { - len = strlen (extensions[i]); - if (len < flen && !strcmp (filename + flen - len, extensions[i])) + flen = strlen(filename); + for (i = 0; i <(sizeof(extensions) / sizeof(extensions[0])); i++) { + len = strlen(extensions[i]); + if (len < flen && !strcmp(filename + flen - len, extensions[i])) return TRUE; } - if (sbd && flen > 4 && !strcmp (filename + flen - 4, ".sbd")) + if (sbd && flen > 4 && !strcmp(filename + flen - 4, ".sbd")) return TRUE; return FALSE; } static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex) +get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex) { struct stat st; char *name; - if (!((CamelStoreClass *) parent_class)->get_folder (store, folder_name, flags, ex)) + if (!((CamelStoreClass *) parent_class)->get_folder(store, folder_name, flags, ex)) return NULL; - name = mbox_folder_name_to_path (store, folder_name); + name = mbox_folder_name_to_path(store, folder_name); - if (stat (name, &st) == -1) { + if (stat(name, &st) == -1) { char *dirname; int fd; if (errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not open file `%s':\n%s"), - name, g_strerror (errno)); - g_free (name); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not open file `%s':\n%s"), + name, g_strerror(errno)); + g_free(name); return NULL; } if ((flags & CAMEL_STORE_FOLDER_CREATE) == 0) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Folder `%s' does not exist."), - folder_name); - g_free (name); + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Folder `%s' does not exist."), + folder_name); + g_free(name); return NULL; } - dirname = g_path_get_dirname (name); - if (camel_mkdir (dirname, 0777) == -1 && errno != EEXIST) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Could not create directory `%s':\n%s"), - dirname, g_strerror (errno)); - g_free (dirname); - g_free (name); + dirname = g_path_get_dirname(name); + if (camel_mkdir(dirname, 0777) == -1 && errno != EEXIST) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Could not create directory `%s':\n%s"), + dirname, g_strerror(errno)); + g_free(dirname); + g_free(name); return NULL; } - g_free (dirname); + g_free(dirname); - fd = open (name, O_WRONLY | O_CREAT | O_APPEND, 0666); + fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666); if (fd == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not create file `%s':\n%s"), - name, g_strerror (errno)); - g_free (name); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not create file `%s':\n%s"), + name, g_strerror(errno)); + g_free(name); return NULL; } - g_free (name); - close (fd); - } else if (!S_ISREG (st.st_mode)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("`%s' is not a regular file."), - name); - g_free (name); + g_free(name); + close(fd); + } else if (!S_ISREG(st.st_mode)) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("`%s' is not a regular file."), + name); + g_free(name); return NULL; } else - g_free (name); + g_free(name); - return camel_mbox_folder_new (store, folder_name, flags, ex); + return camel_mbox_folder_new(store, folder_name, flags, ex); } static void -delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) +delete_folder(CamelStore *store, const char *folder_name, CamelException *ex) { CamelFolderInfo *fi; CamelException lex; @@ -204,48 +204,48 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) char *name, *path; struct stat st; - name = mbox_folder_name_to_path (store, folder_name); - path = g_strdup_printf ("%s.sbd", name); + name = mbox_folder_name_to_path(store, folder_name); + path = g_strdup_printf("%s.sbd", name); - if (rmdir (path) == -1 && errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not delete folder `%s':\n%s"), - folder_name, g_strerror (errno)); - g_free (path); - g_free (name); + if (rmdir(path) == -1 && errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not delete folder `%s':\n%s"), + folder_name, g_strerror(errno)); + g_free(path); + g_free(name); return; } - g_free (path); + g_free(path); - if (stat (name, &st) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not delete folder `%s':\n%s"), - folder_name, g_strerror (errno)); - g_free (name); + if (stat(name, &st) == -1) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not delete folder `%s':\n%s"), + folder_name, g_strerror(errno)); + g_free(name); return; } - if (!S_ISREG (st.st_mode)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("`%s' is not a regular file."), name); - g_free (name); + if (!S_ISREG(st.st_mode)) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("`%s' is not a regular file."), name); + g_free(name); return; } if (st.st_size != 0) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_NON_EMPTY, - _("Folder `%s' is not empty. Not deleted."), - folder_name); - g_free (name); + camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_NON_EMPTY, + _("Folder `%s' is not empty. Not deleted."), + folder_name); + g_free(name); return; } - if (unlink (name) == -1 && errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not delete folder `%s':\n%s"), - name, g_strerror (errno)); - g_free (name); + if (unlink(name) == -1 && errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not delete folder `%s':\n%s"), + name, g_strerror(errno)); + g_free(name); return; } @@ -254,175 +254,175 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) * naming convention is different. Need to find a way for * CamelLocalStore to be able to construct the folder & meta * paths itself */ - path = mbox_folder_name_to_meta_path (store, folder_name, ".ev-summary"); - if (unlink (path) == -1 && errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not delete folder summary file `%s': %s"), - path, g_strerror (errno)); - g_free (path); - g_free (name); + path = mbox_folder_name_to_meta_path(store, folder_name, ".ev-summary"); + if (unlink(path) == -1 && errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not delete folder summary file `%s': %s"), + path, g_strerror(errno)); + g_free(path); + g_free(name); return; } - g_free (path); + g_free(path); - path = mbox_folder_name_to_meta_path (store, folder_name, ".ibex"); - if (camel_text_index_remove (path) == -1 && errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not delete folder index file `%s': %s"), - path, g_strerror (errno)); - g_free (path); - g_free (name); + path = mbox_folder_name_to_meta_path(store, folder_name, ".ibex"); + if (camel_text_index_remove(path) == -1 && errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not delete folder index file `%s': %s"), + path, g_strerror(errno)); + g_free(path); + g_free(name); return; } - g_free (path); + g_free(path); - camel_exception_init (&lex); - if ((lf = camel_store_get_folder (store, folder_name, 0, &lex))) { - camel_object_get (lf, NULL, CAMEL_OBJECT_STATE_FILE, &path, NULL); - camel_object_set (lf, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL); - camel_object_unref (lf); + camel_exception_init(&lex); + if ((lf = camel_store_get_folder(store, folder_name, 0, &lex))) { + camel_object_get(lf, NULL, CAMEL_OBJECT_STATE_FILE, &path, NULL); + camel_object_set(lf, NULL, CAMEL_OBJECT_STATE_FILE, NULL, NULL); + camel_object_unref(lf); } else { - camel_exception_clear (&lex); + camel_exception_clear(&lex); } if (path == NULL) - path = mbox_folder_name_to_meta_path (store, folder_name, ".cmeta"); + path = mbox_folder_name_to_meta_path(store, folder_name, ".cmeta"); - if (unlink (path) == -1 && errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not delete folder meta file `%s': %s"), - path, g_strerror (errno)); + if (unlink(path) == -1 && errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not delete folder meta file `%s': %s"), + path, g_strerror(errno)); - g_free (path); - g_free (name); + g_free(path); + g_free(name); return; } - g_free (path); - g_free (name); + g_free(path); + g_free(name); - fi = g_new0 (CamelFolderInfo, 1); - fi->full_name = g_strdup (folder_name); - fi->name = g_path_get_basename (folder_name); - fi->url = g_strdup_printf ("mbox:%s#%s", ((CamelService *) store)->url->path, folder_name); + fi = g_new0(CamelFolderInfo, 1); + fi->full_name = g_strdup(folder_name); + fi->name = g_path_get_basename(folder_name); + fi->url = g_strdup_printf("mbox:%s#%s",((CamelService *) store)->url->path, folder_name); fi->unread_message_count = -1; - camel_folder_info_build_path (fi, '/'); + camel_folder_info_build_path(fi, '/'); - camel_object_trigger_event (store, "folder_deleted", fi); + camel_object_trigger_event(store, "folder_deleted", fi); - camel_folder_info_free (fi); + camel_folder_info_free(fi); } static CamelFolderInfo * -create_folder (CamelStore *store, const char *parent_name, const char *folder_name, CamelException *ex) +create_folder(CamelStore *store, const char *parent_name, const char *folder_name, CamelException *ex) { /* FIXME: this is almost an exact copy of CamelLocalStore::create_folder() except that we use * different path schemes... need to find a way to share parent's code? */ - const char *toplevel_dir = ((CamelLocalStore *) store)->toplevel_dir; + const char *toplevel_dir =((CamelLocalStore *) store)->toplevel_dir; CamelFolderInfo *info = NULL; char *path, *name, *dir; CamelFolder *folder; struct stat st; if (toplevel_dir[0] != '/') { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Store root %s is not an absolute path"), toplevel_dir); + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Store root %s is not an absolute path"), toplevel_dir); return NULL; } - if (folder_name[0] == '.' || ignore_file (folder_name, TRUE)) { - camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, - _("Cannot create a folder by this name.")); + if (folder_name[0] == '.' || ignore_file(folder_name, TRUE)) { + camel_exception_set(ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot create a folder by this name.")); return NULL; } if (parent_name && *parent_name) - name = g_strdup_printf ("%s/%s", parent_name, folder_name); + name = g_strdup_printf("%s/%s", parent_name, folder_name); else - name = g_strdup (folder_name); + name = g_strdup(folder_name); - path = mbox_folder_name_to_path (store, name); + path = mbox_folder_name_to_path(store, name); - dir = g_path_get_dirname (path); - if (camel_mkdir (dir, 0777) == -1 && errno != EEXIST) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create directory `%s': %s."), - dir, g_strerror (errno)); + dir = g_path_get_dirname(path); + if (camel_mkdir(dir, 0777) == -1 && errno != EEXIST) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create directory `%s': %s."), + dir, g_strerror(errno)); - g_free (path); - g_free (name); - g_free (dir); + g_free(path); + g_free(name); + g_free(dir); return NULL; } - g_free (dir); + g_free(dir); - if (stat (path, &st) == 0 || errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Cannot create folder: %s: %s"), - path, errno ? g_strerror (errno) : - _("Folder already exists")); + if (stat(path, &st) == 0 || errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Cannot create folder: %s: %s"), + path, errno ? g_strerror(errno) : + _("Folder already exists")); - g_free (path); - g_free (name); + g_free(path); + g_free(name); return NULL; } - g_free (path); + g_free(path); - folder = ((CamelStoreClass *) ((CamelObject *) store)->klass)->get_folder (store, name, CAMEL_STORE_FOLDER_CREATE, ex); + folder =((CamelStoreClass *)((CamelObject *) store)->klass)->get_folder(store, name, CAMEL_STORE_FOLDER_CREATE, ex); if (folder) { - camel_object_unref (folder); - info = ((CamelStoreClass *) ((CamelObject *) store)->klass)->get_folder_info (store, name, 0, ex); + camel_object_unref(folder); + info =((CamelStoreClass *)((CamelObject *) store)->klass)->get_folder_info(store, name, 0, ex); } - g_free (name); + g_free(name); return info; } static int -xrename (CamelStore *store, const char *old_name, const char *new_name, const char *ext, gboolean missingok) +xrename(CamelStore *store, const char *old_name, const char *new_name, const char *ext, gboolean missingok) { - const char *toplevel_dir = ((CamelLocalStore *) store)->toplevel_dir; + const char *toplevel_dir =((CamelLocalStore *) store)->toplevel_dir; char *oldpath, *newpath; struct stat st; int ret = -1; int err = 0; if (ext != NULL) { - oldpath = camel_mbox_folder_get_meta_path (toplevel_dir, old_name, ext); - newpath = camel_mbox_folder_get_meta_path (toplevel_dir, new_name, ext); + oldpath = camel_mbox_folder_get_meta_path(toplevel_dir, old_name, ext); + newpath = camel_mbox_folder_get_meta_path(toplevel_dir, new_name, ext); } else { - oldpath = camel_mbox_folder_get_full_path (toplevel_dir, old_name); - newpath = camel_mbox_folder_get_full_path (toplevel_dir, new_name); + oldpath = camel_mbox_folder_get_full_path(toplevel_dir, old_name); + newpath = camel_mbox_folder_get_full_path(toplevel_dir, new_name); } - if (stat (oldpath, &st) == -1) { + if (stat(oldpath, &st) == -1) { if (missingok && errno == ENOENT) { ret = 0; } else { err = errno; ret = -1; } - } else if (S_ISDIR (st.st_mode)) { + } else if (S_ISDIR(st.st_mode)) { /* use rename for dirs */ - if (rename (oldpath, newpath) == 0 || stat (newpath, &st) == 0) { + if (rename(oldpath, newpath) == 0 || stat(newpath, &st) == 0) { ret = 0; } else { err = errno; ret = -1; } - } else if (link (oldpath, newpath) == 0 /* and link for files */ - || (stat (newpath, &st) == 0 && st.st_nlink == 2)) { - if (unlink (oldpath) == 0) { + } else if (link(oldpath, newpath) == 0 /* and link for files */ + ||(stat(newpath, &st) == 0 && st.st_nlink == 2)) { + if (unlink(oldpath) == 0) { ret = 0; } else { err = errno; - unlink (newpath); + unlink(newpath); ret = -1; } } else { @@ -430,120 +430,119 @@ xrename (CamelStore *store, const char *old_name, const char *new_name, const ch ret = -1; } - g_free (oldpath); - g_free (newpath); + g_free(oldpath); + g_free(newpath); return ret; } static void -rename_folder (CamelStore *store, const char *old, const char *new, CamelException *ex) +rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex) { CamelLocalFolder *folder = NULL; - char *oldibex, *newibex, *newdir, *sbd; + char *oldibex, *newibex, *newdir; int errnosav; - if (new[0] == '.' || ignore_file (new, TRUE)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + if (new[0] == '.' || ignore_file(new, TRUE)) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("The new folder name is illegal.")); return; } /* try to rollback failures, has obvious races */ - oldibex = mbox_folder_name_to_meta_path (store, old, ".ibex"); - newibex = mbox_folder_name_to_meta_path (store, new, ".ibex"); + oldibex = mbox_folder_name_to_meta_path(store, old, ".ibex"); + newibex = mbox_folder_name_to_meta_path(store, new, ".ibex"); - newdir = g_path_get_dirname (newibex); - if (camel_mkdir (newdir, 0777) == -1) { + newdir = g_path_get_dirname(newibex); + if (camel_mkdir(newdir, 0777) == -1) { if (errno != EEXIST) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not rename `%s': `%s': %s"), - old, new, g_strerror (errno)); - g_free (oldibex); - g_free (newibex); - g_free (newdir); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not rename `%s': `%s': %s"), + old, new, g_strerror(errno)); + g_free(oldibex); + g_free(newibex); + g_free(newdir); return; } - g_free (newdir); + g_free(newdir); newdir = NULL; } - folder = camel_object_bag_get (store->folders, old); + folder = camel_object_bag_get(store->folders, old); if (folder && folder->index) { - if (camel_index_rename (folder->index, newibex) == -1 && errno != ENOENT) { + if (camel_index_rename(folder->index, newibex) == -1 && errno != ENOENT) { errnosav = errno; goto ibex_failed; } } else { /* TODO: camel_text_index_rename should find out if we have an active index itself? */ - if (camel_text_index_rename (oldibex, newibex) == -1 && errno != ENOENT) { + if (camel_text_index_rename(oldibex, newibex) == -1 && errno != ENOENT) { errnosav = errno; goto ibex_failed; } } - if (xrename (store, old, new, ".ev-summary", TRUE) == -1) { + if (xrename(store, old, new, ".ev-summary", TRUE) == -1) { errnosav = errno; goto summary_failed; } + + if (xrename(store, old, new, ".cmeta", TRUE) == -1) { + errnosav = errno; + goto cmeta_failed; + } - if (xrename (store, old, new, ".sbd", TRUE) == -1) { + if (xrename(store, old, new, ".sbd", TRUE) == -1) { errnosav = errno; goto subdir_failed; } - if (xrename (store, old, new, NULL, FALSE) == -1) { + if (xrename(store, old, new, NULL, FALSE) == -1) { errnosav = errno; goto base_failed; } - g_free (oldibex); - g_free (newibex); + g_free(oldibex); + g_free(newibex); if (folder) - camel_object_unref (folder); + camel_object_unref(folder); return; - base_failed: - - xrename (store, new, old, ".ev-summary", TRUE); - - subdir_failed: - - xrename (store, new, old, ".sbd", TRUE); - - summary_failed: - +base_failed: + xrename(store, new, old, ".sbd", TRUE); +subdir_failed: + xrename(store, new, old, ".cmeta", TRUE); +cmeta_failed: + xrename(store, new, old, ".ev-summary", TRUE); +summary_failed: if (folder) { if (folder->index) - camel_index_rename (folder->index, oldibex); + camel_index_rename(folder->index, oldibex); } else - camel_text_index_rename (newibex, oldibex); - - ibex_failed: - + camel_text_index_rename(newibex, oldibex); +ibex_failed: if (newdir) { /* newdir is only non-NULL if we needed to mkdir */ - rmdir (newdir); - g_free (newdir); + rmdir(newdir); + g_free(newdir); } - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not rename '%s' to %s: %s"), - old, new, g_strerror (errnosav)); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not rename '%s' to %s: %s"), + old, new, g_strerror(errnosav)); - g_free (newibex); - g_free (oldibex); + g_free(newibex); + g_free(oldibex); if (folder) - camel_object_unref (folder); + camel_object_unref(folder); } - /* used to find out where we've visited already */ struct _inode { dev_t dnode; @@ -551,7 +550,7 @@ struct _inode { }; static guint -inode_hash (const void *d) +inode_hash(const void *d) { const struct _inode *v = d; @@ -559,7 +558,7 @@ inode_hash (const void *d) } static gboolean -inode_equal (const void *a, const void *b) +inode_equal(const void *a, const void *b) { const struct _inode *v1 = a, *v2 = b; @@ -567,14 +566,14 @@ inode_equal (const void *a, const void *b) } static void -inode_free (void *k, void *v, void *d) +inode_free(void *k, void *v, void *d) { - g_free (k); + g_free(k); } static CamelFolderInfo * -scan_dir (CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const char *root, - const char *name, guint32 flags, CamelException *ex) +scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const char *root, + const char *name, guint32 flags, CamelException *ex) { CamelFolderInfo *folders, *tail, *fi; GHashTable *folder_hash; @@ -583,16 +582,16 @@ scan_dir (CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const tail = folders = NULL; - if (!(dir = opendir (root))) + if (!(dir = opendir(root))) return NULL; - folder_hash = g_hash_table_new (g_str_hash, g_str_equal); + folder_hash = g_hash_table_new(g_str_hash, g_str_equal); /* FIXME: it would be better if we queue'd up the recursive * scans till the end so that we can limit the number of * directory descriptors open at any given time... */ - while ((dent = readdir (dir))) { + while ((dent = readdir(dir))) { char *short_name, *full_name, *path, *ext; CamelFolder *folder; struct stat st; @@ -601,68 +600,68 @@ scan_dir (CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const if (dent->d_name[0] == '.') continue; - if (ignore_file (dent->d_name, FALSE)) + if (ignore_file(dent->d_name, FALSE)) continue; - path = g_strdup_printf ("%s/%s", root, dent->d_name); - if (stat (path, &st) == -1) { - g_free (path); + path = g_strdup_printf("%s/%s", root, dent->d_name); + if (stat(path, &st) == -1) { + g_free(path); continue; } - if (S_ISDIR (st.st_mode)) { + if (S_ISDIR(st.st_mode)) { struct _inode in = { st.st_dev, st.st_ino }; - if (g_hash_table_lookup (visited, &in)) { - g_free (path); + if (g_hash_table_lookup(visited, &in)) { + g_free(path); continue; } } - short_name = g_strdup (dent->d_name); - if ((ext = strrchr (short_name, '.')) && !strcmp (ext, ".sbd")) + short_name = g_strdup(dent->d_name); + if ((ext = strrchr(short_name, '.')) && !strcmp(ext, ".sbd")) *ext = '\0'; if (name != NULL) - full_name = g_strdup_printf ("%s/%s", name, short_name); + full_name = g_strdup_printf("%s/%s", name, short_name); else - full_name = g_strdup (short_name); + full_name = g_strdup(short_name); - if (!S_ISDIR (st.st_mode)) { - folder = camel_object_bag_get (store->folders, full_name); + if (!S_ISDIR(st.st_mode)) { + folder = camel_object_bag_get(store->folders, full_name); if (folder) { if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0) - camel_folder_refresh_info (folder, NULL); - unread = camel_folder_get_unread_message_count (folder); - camel_object_unref (folder); + camel_folder_refresh_info(folder, NULL); + unread = camel_folder_get_unread_message_count(folder); + camel_object_unref(folder); } } - if ((fi = g_hash_table_lookup (folder_hash, short_name)) != NULL) { - g_free (short_name); - g_free (full_name); + if ((fi = g_hash_table_lookup(folder_hash, short_name)) != NULL) { + g_free(short_name); + g_free(full_name); - if (S_ISDIR (st.st_mode)) { - fi->flags = (fi->flags & ~CAMEL_FOLDER_NOCHILDREN) | CAMEL_FOLDER_CHILDREN; + if (S_ISDIR(st.st_mode)) { + fi->flags =(fi->flags & ~CAMEL_FOLDER_NOCHILDREN) | CAMEL_FOLDER_CHILDREN; } else { fi->unread_message_count = unread; fi->flags &= ~CAMEL_FOLDER_NOSELECT; - if ((ext = strchr (fi->url, ';')) && !strncmp (ext, ";noselect=yes", 13)) - memmove (ext, ext + 13, strlen (ext + 13) + 1); + if ((ext = strchr(fi->url, ';')) && !strncmp(ext, ";noselect=yes", 13)) + memmove(ext, ext + 13, strlen(ext + 13) + 1); } } else { - fi = g_new0 (CamelFolderInfo, 1); + fi = g_new0(CamelFolderInfo, 1); fi->parent = parent; /* add ";noselect=yes" if we haven't found the mbox file yet. when we find it, remove the noselect */ - fi->url = g_strdup_printf ("mbox:%s%s#%s", ((CamelService *) store)->url->path, - S_ISDIR (st.st_mode) ? ";noselect=yes" : "", full_name); + fi->url = g_strdup_printf("mbox:%s%s#%s",((CamelService *) store)->url->path, + S_ISDIR(st.st_mode) ? ";noselect=yes" : "", full_name); fi->name = short_name; fi->full_name = full_name; - fi->path = g_strdup_printf ("/%s", full_name); + fi->path = g_strdup_printf("/%s", full_name); fi->unread_message_count = unread; - if (S_ISDIR (st.st_mode)) + if (S_ISDIR(st.st_mode)) fi->flags = CAMEL_FOLDER_NOSELECT; else fi->flags = CAMEL_FOLDER_NOCHILDREN; @@ -674,36 +673,36 @@ scan_dir (CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const tail = fi; - g_hash_table_insert (folder_hash, fi->name, fi); + g_hash_table_insert(folder_hash, fi->name, fi); } - if ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) && S_ISDIR (st.st_mode)) { + if ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) && S_ISDIR(st.st_mode)) { struct _inode in = { st.st_dev, st.st_ino }; - if (g_hash_table_lookup (visited, &in) == NULL) { - struct _inode *inew = g_new (struct _inode, 1); + if (g_hash_table_lookup(visited, &in) == NULL) { + struct _inode *inew = g_new(struct _inode, 1); *inew = in; - g_hash_table_insert (visited, inew, inew); + g_hash_table_insert(visited, inew, inew); - if ((fi->child = scan_dir (store, visited, fi, path, fi->full_name, flags, ex))) + if ((fi->child = scan_dir(store, visited, fi, path, fi->full_name, flags, ex))) fi->flags |= CAMEL_FOLDER_CHILDREN; } } - g_free (path); + g_free(path); } - closedir (dir); + closedir(dir); - g_hash_table_destroy (folder_hash); + g_hash_table_destroy(folder_hash); return folders; } static CamelFolderInfo * -get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex) +get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelException *ex) { GHashTable *visited; struct _inode *inode; @@ -715,74 +714,74 @@ get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelExcepti int unread = -1; top = top ? top : ""; - path = mbox_folder_name_to_path (store, top); + path = mbox_folder_name_to_path(store, top); if (*top == '\0') { /* requesting root dir scan */ - if (stat (path, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_free (path); + if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { + g_free(path); return NULL; } - visited = g_hash_table_new (inode_hash, inode_equal); + visited = g_hash_table_new(inode_hash, inode_equal); - inode = g_new (struct _inode, 1); + inode = g_new(struct _inode, 1); inode->dnode = st.st_dev; inode->inode = st.st_ino; - g_hash_table_insert (visited, inode, inode); + g_hash_table_insert(visited, inode, inode); - fi = scan_dir (store, visited, NULL, path, NULL, flags, ex); - g_hash_table_foreach (visited, inode_free, NULL); - g_hash_table_destroy (visited); - g_free (path); + fi = scan_dir(store, visited, NULL, path, NULL, flags, ex); + g_hash_table_foreach(visited, inode_free, NULL); + g_hash_table_destroy(visited); + g_free(path); return fi; } /* requesting scan of specific folder */ - if (stat (path, &st) == -1 || !S_ISREG (st.st_mode)) { - g_free (path); + if (stat(path, &st) == -1 || !S_ISREG(st.st_mode)) { + g_free(path); return NULL; } - visited = g_hash_table_new (inode_hash, inode_equal); + visited = g_hash_table_new(inode_hash, inode_equal); - if (!(base = strrchr (top, '/'))) + if (!(base = strrchr(top, '/'))) base = top; else base++; - folder = camel_object_bag_get (store->folders, top); + folder = camel_object_bag_get(store->folders, top); if (folder) { if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0) - camel_folder_refresh_info (folder, NULL); - unread = camel_folder_get_unread_message_count (folder); - camel_object_unref (folder); + camel_folder_refresh_info(folder, NULL); + unread = camel_folder_get_unread_message_count(folder); + camel_object_unref(folder); } - fi = g_new0 (CamelFolderInfo, 1); + fi = g_new0(CamelFolderInfo, 1); fi->parent = NULL; - fi->url = g_strdup_printf ("mbox:%s#%s", ((CamelService *) store)->url->path, top); - fi->name = g_strdup (base); - fi->full_name = g_strdup (top); + fi->url = g_strdup_printf("mbox:%s#%s",((CamelService *) store)->url->path, top); + fi->name = g_strdup(base); + fi->full_name = g_strdup(top); fi->unread_message_count = unread; - fi->path = g_strdup_printf ("/%s", top); + fi->path = g_strdup_printf("/%s", top); - subdir = g_strdup_printf ("%s.sbd", path); - if (stat (subdir, &st) == 0 && S_ISDIR (st.st_mode)) - fi->child = scan_dir (store, visited, fi, subdir, top, flags, ex); + subdir = g_strdup_printf("%s.sbd", path); + if (stat(subdir, &st) == 0 && S_ISDIR(st.st_mode)) + fi->child = scan_dir(store, visited, fi, subdir, top, flags, ex); if (fi->child) fi->flags |= CAMEL_FOLDER_CHILDREN; else fi->flags |= CAMEL_FOLDER_NOCHILDREN; - g_free (subdir); + g_free(subdir); - g_hash_table_foreach (visited, inode_free, NULL); - g_hash_table_destroy (visited); - g_free (path); + g_hash_table_foreach(visited, inode_free, NULL); + g_hash_table_destroy(visited); + g_free(path); return fi; } -- cgit v1.2.3