From fac0dbd69c7d8a6807d51cc12615de88b7a900be Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 16 Oct 2001 21:47:34 +0000 Subject: If CAMEL_DEBUG is defined, print some useful ref/unref info. 2001-10-16 Jeffrey Stedfast * camel-object.[c,h]: If CAMEL_DEBUG is defined, print some useful ref/unref info. * providers/imap/camel-imap-store.c (delete_folder): Fixed an assignment warning. * camel-uid-cache.c (camel_uid_cache_new): Make sure that the parent directory exists before trying to open the filename, if it doesn't, create it. svn path=/trunk/; revision=13707 --- camel/camel-uid-cache.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'camel/camel-uid-cache.c') diff --git a/camel/camel-uid-cache.c b/camel/camel-uid-cache.c index 15e463c157..5f88fd624b 100644 --- a/camel/camel-uid-cache.c +++ b/camel/camel-uid-cache.c @@ -43,6 +43,31 @@ struct _uid_state { static void free_uid (gpointer key, gpointer value, gpointer data); static void maybe_write_uid (gpointer key, gpointer value, gpointer data); + +static int +mkdir_heir (const char *path, mode_t mode) +{ + char *copy, *p; + + p = copy = g_strdup (path); + do { + p = strchr (p + 1, '/'); + if (p) + *p = '\0'; + if (access (copy, F_OK) == -1) { + if (mkdir (copy, mode) == -1) { + g_free (copy); + return -1; + } + } + if (p) + *p = '/'; + } while (p); + + g_free (copy); + return 0; +} + /** * camel_uid_cache_new: * @filename: path to load the cache from @@ -58,9 +83,13 @@ camel_uid_cache_new (const char *filename) { CamelUIDCache *cache; struct stat st; - char *buf, **uids; + char *dirname, *buf, **uids; int fd, i; + dirname = g_dirname (filename); + mkdir_heir (dirname, 0700); + g_free (dirname); + fd = open (filename, O_RDWR | O_CREAT, 0700); if (fd == -1) return NULL; -- cgit v1.2.3