diff options
Diffstat (limited to 'camel/providers/local')
-rw-r--r-- | camel/providers/local/camel-local-store.c | 34 | ||||
-rw-r--r-- | camel/providers/local/camel-maildir-store.c | 15 | ||||
-rw-r--r-- | camel/providers/local/camel-mbox-store.c | 28 | ||||
-rw-r--r-- | camel/providers/local/camel-mh-store.c | 18 |
4 files changed, 50 insertions, 45 deletions
diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c index 09b644a318..fae124e448 100644 --- a/camel/providers/local/camel-local-store.c +++ b/camel/providers/local/camel-local-store.c @@ -39,6 +39,7 @@ #include "camel-local-folder.h" #include <camel/camel-text-index.h> +#include <camel/camel-file-utils.h> #define d(x) @@ -129,10 +130,9 @@ camel_local_store_get_toplevel_dir (CamelLocalStore *store) static CamelFolder * get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelException * ex) { - struct stat st; char *path = ((CamelLocalStore *)store)->toplevel_dir; - char *sub, *slash; - + struct stat st; + if (path[0] != '/') { camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, _("Store root %s is not an absolute path"), path); @@ -155,27 +155,15 @@ get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelExce path, g_strerror (errno)); return NULL; } - + /* need to create the dir heirarchy */ - sub = g_alloca (strlen (path) + 1); - strcpy (sub, path); - slash = sub; - do { - slash = strchr (slash + 1, '/'); - if (slash) - *slash = 0; - if (stat (sub, &st) == -1) { - if (errno != ENOENT || mkdir (sub, 0700) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Cannot get folder: %s: %s"), - path, g_strerror (errno)); - return NULL; - } - } - if (slash) - *slash = '/'; - } while (slash); - + if (camel_mkdir (path, 0777) == -1 && errno != EEXIST) { + camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Cannot get folder: %s: %s"), + path, g_strerror (errno)); + return NULL; + } + return (CamelFolder *) 0xdeadbeef; } diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c index c84c37158c..0eff01f1d2 100644 --- a/camel/providers/local/camel-maildir-store.c +++ b/camel/providers/local/camel-maildir-store.c @@ -103,18 +103,19 @@ get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelExce if (stat(name, &st) == -1) { if (errno != ENOENT) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not open folder `%s':\n%s"), + _("Cannot get folder `%s': %s"), folder_name, g_strerror (errno)); } else if ((flags & CAMEL_STORE_FOLDER_CREATE) == 0) { camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Folder `%s' does not exist."), folder_name); + _("Cannot get folder `%s': folder does not exist."), + folder_name); } else { if (mkdir(name, 0700) != 0 || mkdir(tmp, 0700) != 0 || mkdir(cur, 0700) != 0 || mkdir(new, 0700) != 0) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not create folder `%s':\n%s"), + _("Cannot create folder `%s': %s"), folder_name, g_strerror (errno)); rmdir(tmp); rmdir(cur); @@ -128,8 +129,12 @@ get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelExce || stat(tmp, &st) != 0 || !S_ISDIR(st.st_mode) || stat(cur, &st) != 0 || !S_ISDIR(st.st_mode) || stat(new, &st) != 0 || !S_ISDIR(st.st_mode)) { - camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("`%s' is not a maildir directory."), name); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot get folder `%s': not a maildir directory."), name); + } else if (flags & CAMEL_STORE_FOLDER_EXCL) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot create folder `%s': folder exists."), + folder_name); } else { folder = camel_maildir_folder_new(store, folder_name, flags, ex); } diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c index 1eb827d823..b1a5664c33 100644 --- a/camel/providers/local/camel-mbox-store.c +++ b/camel/providers/local/camel-mbox-store.c @@ -150,15 +150,15 @@ get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelExcep if (errno != ENOENT) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not open file `%s':\n%s"), - name, g_strerror(errno)); + _("Cannot get folder `%s': %s"), + folder_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."), + _("Cannot get folder `%s': folder does not exist."), folder_name); g_free(name); return NULL; @@ -166,9 +166,9 @@ get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelExcep 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)); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot create folder `%s': %s"), + folder_name, g_strerror (errno)); g_free(dirname); g_free(name); return NULL; @@ -179,8 +179,8 @@ get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelExcep 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)); + _("Cannot create folder `%s': %s"), + folder_name, g_strerror (errno)); g_free(name); return NULL; } @@ -188,11 +188,17 @@ get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelExcep 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); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot get folder `%s': not a regular file."), + folder_name); g_free(name); return NULL; + } else if (flags & CAMEL_STORE_FOLDER_EXCL) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot create folder `%s': folder exists."), + folder_name); + g_free (name); + return NULL; } else g_free(name); diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c index 73a3d2046f..b16c140a66 100644 --- a/camel/providers/local/camel-mh-store.c +++ b/camel/providers/local/camel-mh-store.c @@ -199,21 +199,22 @@ get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelExce if (stat(name, &st) == -1) { if (errno != ENOENT) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not open folder `%s':\n%s"), + _("Cannot get folder `%s': %s"), folder_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); + _("Cannot get folder `%s': folder does not exist."), + folder_name); g_free (name); return NULL; } - if (mkdir(name, 0700) != 0) { + if (mkdir(name, 0777) != 0) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, - _("Could not create folder `%s':\n%s"), + _("Could not create folder `%s': %s"), folder_name, g_strerror (errno)); g_free (name); return NULL; @@ -223,13 +224,18 @@ get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelExce /* FIXME: throw exception on error */ if (((CamelMhStore *)store)->flags & CAMEL_MH_DOTFOLDERS) folders_update(((CamelLocalStore *)store)->toplevel_dir, folder_name, UPDATE_ADD); - } else if (!S_ISDIR(st.st_mode)) { camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("`%s' is not a directory."), name); + _("Cannot get folder `%s': not a directory."), folder_name); + g_free (name); + return NULL; + } else if (flags & CAMEL_STORE_FOLDER_EXCL) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Cannot create folder `%s': folder exists."), folder_name); g_free (name); return NULL; } + g_free(name); return camel_mh_folder_new(store, folder_name, flags, ex); |