aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-02-14 03:45:31 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-02-14 03:45:31 +0800
commitfdacdc0bb9a57096680d44ff92aa24ff997bbff4 (patch)
treecc85ea0d2d800d3e660fb062570d0d9b79414564 /camel
parentbab092a05cc6b1c7d11954bfb65d2b0aa6d1ce6f (diff)
downloadgsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.tar
gsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.tar.gz
gsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.tar.bz2
gsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.tar.lz
gsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.tar.xz
gsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.tar.zst
gsoc2013-evolution-fdacdc0bb9a57096680d44ff92aa24ff997bbff4.zip
Same.
2004-02-13 Jeffrey Stedfast <fejj@ximian.com> * providers/imap/camel-imap-store.c (get_folder_online): Same. * providers/local/camel-mh-store.c (get_folder): Same as maildir changes. * providers/local/camel-maildir-store.c (get_folder): Make exceptions strings consistanmt with the mbox exception strings (and vise versa). Also handle the CAMEL_STORE_FOLDER_EXCL flag. * providers/local/camel-mbox-store.c (get_folder): Check CAMEL_STORE_FOLDER_EXCL flag. * providers/local/camel-local-store.c (get_folder): Simplified by using camel_mkdir instead of doing it manually. * camel-store.c (camel_store_get_folder): If the folder exists in the cache and the O_EXCL flag was passed, return NULL and set an exception. * camel-store.h: Added a new CAMEL_STORE_FOLDER_EXCL flag for use with get_folder(). svn path=/trunk/; revision=24738
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog24
-rw-r--r--camel/camel-store.c23
-rw-r--r--camel/camel-store.h7
-rw-r--r--camel/providers/imap/camel-imap-store.c10
-rw-r--r--camel/providers/local/camel-local-store.c34
-rw-r--r--camel/providers/local/camel-maildir-store.c15
-rw-r--r--camel/providers/local/camel-mbox-store.c28
-rw-r--r--camel/providers/local/camel-mh-store.c18
8 files changed, 107 insertions, 52 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index a3c56f5ef5..893acdcebd 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,27 @@
+2004-02-13 Jeffrey Stedfast <fejj@ximian.com>
+
+ * providers/imap/camel-imap-store.c (get_folder_online): Same.
+
+ * providers/local/camel-mh-store.c (get_folder): Same as maildir
+ changes.
+
+ * providers/local/camel-maildir-store.c (get_folder): Make
+ exceptions strings consistanmt with the mbox exception strings
+ (and vise versa). Also handle the CAMEL_STORE_FOLDER_EXCL flag.
+
+ * providers/local/camel-mbox-store.c (get_folder): Check
+ CAMEL_STORE_FOLDER_EXCL flag.
+
+ * providers/local/camel-local-store.c (get_folder): Simplified by
+ using camel_mkdir instead of doing it manually.
+
+ * camel-store.c (camel_store_get_folder): If the folder exists in
+ the cache and the O_EXCL flag was passed, return NULL and set an
+ exception.
+
+ * camel-store.h: Added a new CAMEL_STORE_FOLDER_EXCL flag for use
+ with get_folder().
+
2004-02-12 Jeffrey Stedfast <fejj@ximian.com>
* camel-file-utils.c (camel_file_util_encode_string): Since
diff --git a/camel/camel-store.c b/camel/camel-store.c
index 40be4d085b..340f95f5cd 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -230,22 +230,35 @@ camel_store_get_folder (CamelStore *store, const char *folder_name, guint32 flag
g_return_val_if_fail (folder_name != NULL, NULL);
+ /* O_EXCL doesn't make sense if we aren't requesting to also create the folder if it doesn't exist */
+ if (!(flags & CAMEL_STORE_FOLDER_CREATE))
+ flags &= ~CAMEL_STORE_FOLDER_EXCL;
+
CAMEL_STORE_LOCK(store, folder_lock);
- if (store->folders)
+ if (store->folders) {
/* Try cache first. */
folder = camel_object_bag_reserve(store->folders, folder_name);
+ if (folder && (flags & CAMEL_STORE_FOLDER_EXCL)) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot create folder `%s': folder exists"),
+ folder_name);
+
+ camel_object_unref (folder);
+ return NULL;
+ }
+ }
if (!folder) {
- if ((store->flags & CAMEL_STORE_VTRASH) && strcmp(folder_name, CAMEL_VTRASH_NAME) == 0)
+ if ((store->flags & CAMEL_STORE_VTRASH) && strcmp(folder_name, CAMEL_VTRASH_NAME) == 0) {
folder = CS_CLASS(store)->get_trash(store, ex);
- else if ((store->flags & CAMEL_STORE_VJUNK) && strcmp(folder_name, CAMEL_VJUNK_NAME) == 0)
+ } else if ((store->flags & CAMEL_STORE_VJUNK) && strcmp(folder_name, CAMEL_VJUNK_NAME) == 0) {
folder = CS_CLASS(store)->get_junk(store, ex);
- else {
+ } else {
folder = CS_CLASS (store)->get_folder(store, folder_name, flags, ex);
if (folder) {
CamelVeeFolder *vfolder;
-
+
if ((store->flags & CAMEL_STORE_VTRASH)
&& (vfolder = camel_object_bag_get(store->folders, CAMEL_VTRASH_NAME))) {
camel_vee_folder_add_folder(vfolder, folder);
diff --git a/camel/camel-store.h b/camel/camel-store.h
index c936517fda..d0df14f2a7 100644
--- a/camel/camel-store.h
+++ b/camel/camel-store.h
@@ -107,8 +107,11 @@ struct _CamelStore
/* open mode for folder */
#define CAMEL_STORE_FOLDER_CREATE (1<<0)
-#define CAMEL_STORE_FOLDER_BODY_INDEX (1<<1)
-#define CAMEL_STORE_FOLDER_PRIVATE (1<<2) /* a private folder, that shouldn't show up in unmatched/folder info's, etc */
+#define CAMEL_STORE_FOLDER_EXCL (1<<1)
+#define CAMEL_STORE_FOLDER_BODY_INDEX (1<<2)
+#define CAMEL_STORE_FOLDER_PRIVATE (1<<3) /* a private folder, that shouldn't show up in unmatched/folder info's, etc */
+
+#define CAMEL_STORE_FOLDER_CREATE_EXCL (CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_EXCL)
#define CAMEL_STORE_FOLDER_INFO_FAST (1 << 0)
#define CAMEL_STORE_FOLDER_INFO_RECURSIVE (1 << 1)
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 310d54ad35..7b86773b4c 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -1762,6 +1762,16 @@ get_folder_online (CamelStore *store, const char *folder_name,
CAMEL_SERVICE_UNLOCK (imap_store, connect_lock);
return NULL;
}
+ } else if (flags & CAMEL_STORE_FOLDER_EXCL) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot create folder `%s': folder exists."),
+ folder_name);
+
+ camel_imap_response_free_without_processing (imap_store, response);
+
+ CAMEL_SERVICE_UNLOCK (imap_store, connect_lock);
+
+ return NULL;
}
storage_path = g_strdup_printf("%s/folders", imap_store->storage_path);
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);