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
This commit is contained in:
Jeffrey Stedfast
2004-02-13 19:45:31 +00:00
committed by Jeffrey Stedfast
parent bab092a05c
commit fdacdc0bb9
8 changed files with 107 additions and 52 deletions

View File

@ -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

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);