diff options
author | Not Zed <NotZed@Ximian.com> | 2001-06-18 22:36:44 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-06-18 22:36:44 +0800 |
commit | e905364beee184b99637029de7151b43339b2e1c (patch) | |
tree | 70761b71502abd250930cedeacc6fa191dac2bff /camel/providers | |
parent | 5255cb6d496630adb35934b850d8b064c3121c74 (diff) | |
download | gsoc2013-evolution-e905364beee184b99637029de7151b43339b2e1c.tar.gz gsoc2013-evolution-e905364beee184b99637029de7151b43339b2e1c.tar.zst gsoc2013-evolution-e905364beee184b99637029de7151b43339b2e1c.zip |
Only create a missing uid if we have indexing turned on.
2001-06-18 Not Zed <NotZed@Ximian.com>
* camel-folder-summary.c
(camel_folder_summary_info_new_from_parser): Only create a missing
uid if we have indexing turned on.
* camel-lock-helper.c (setup_process): Function to setup
process/sanity/security checks. Change to the real uid as soon as
we can.
(lock_path): First try to lock as the real uid, if that fails, try
the root uid.
(unlock_id): Unlock as the uid we created the lock as.
* Makefile.am (INCLUDES): Added -DCAMEL_SBINDIR for lock helper
location.
* providers/local/camel-spool-folder.c (spool_lock): Implemented,
using lock helper locking. Need to work out if the locking
requires a root created lock?
(spool_unlock): Likewise.
2001-06-15 Not Zed <NotZed@Ximian.com>
* camel-lock-helper.c: Setuid Lock helper process. Creates and manages
.locks, keeping them active, removing them, etc. What real perms it
needs is a little system dependent.
2001-06-14 Not Zed <NotZed@Ximian.com>
* providers/local/camel-maildir-store.c (get_folder_info): Implement.
(scan_dir): Does the work of scanning for maildir directories.
2001-06-13 Not Zed <NotZed@Ximian.com>
* providers/local/camel-spool-store.c (get_folder_info):
Implemented, just returns a hardcoded INBOX folder.
(free_folder_info): implemented, free's the 1 possible level of
folder info.
* providers/local/camel-spool-folder.c
(camel_spool_folder_construct): Set the real unread message
count on the folder_created thing.
svn path=/trunk/; revision=10261
Diffstat (limited to 'camel/providers')
-rw-r--r-- | camel/providers/local/camel-maildir-store.c | 114 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-folder.c | 60 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-folder.h | 2 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-store.c | 91 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-store.h | 2 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-summary.c | 13 |
6 files changed, 238 insertions, 44 deletions
diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c index 8fa4454485..b85bdc3aeb 100644 --- a/camel/providers/local/camel-maildir-store.c +++ b/camel/providers/local/camel-maildir-store.c @@ -46,6 +46,8 @@ static CamelLocalStoreClass *parent_class = NULL; 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 CamelFolderInfo * get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex); + static void camel_maildir_store_class_init(CamelObjectClass * camel_maildir_store_class) { CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS(camel_maildir_store_class); @@ -56,6 +58,9 @@ static void camel_maildir_store_class_init(CamelObjectClass * camel_maildir_stor /* virtual method overload, use defaults for most */ camel_store_class->get_folder = get_folder; camel_store_class->delete_folder = delete_folder; + + camel_store_class->get_folder_info = get_folder_info; + camel_store_class->free_folder_info = camel_store_free_folder_info_full; } CamelType camel_maildir_store_get_type(void) @@ -198,3 +203,112 @@ static void delete_folder(CamelStore * store, const char *folder_name, CamelExce g_free(cur); g_free(new); } + +static CamelFolderInfo *camel_folder_info_new(const char *url, const char *full, const char *name, int unread) +{ + CamelFolderInfo *fi; + + fi = g_malloc0(sizeof(*fi)); + fi->url = g_strdup(url); + fi->full_name = g_strdup(full); + fi->name = g_strdup(name); + fi->unread_message_count = unread; + + return fi; +} + +static int scan_dir(char *root, const char *path, guint32 flags, CamelFolderInfo *parent, CamelFolderInfo **fip, CamelException *ex) +{ + DIR *dir; + struct dirent *d; + char *name, *uri, *tmp, *cur, *new; + const char *base; + CamelFolderInfo *fi = NULL; + struct stat st; + + /* look for folders matching the right structure, recursively */ + name = g_strdup_printf("%s/%s", root, path); + + printf("checking dir '%s' part '%s' for maildir content\n", root, path); + + tmp = g_strdup_printf("%s/tmp", name); + cur = g_strdup_printf("%s/cur", name); + new = g_strdup_printf("%s/new", name); + + if (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)) { + uri = g_strdup_printf("maildir://%s#%s", root, path); + base = strrchr(path, '/'); + if (base) + base++; + else + base = path; + fi = camel_folder_info_new(uri, path, base, -1); + + printf("found! uri = %s\n", fi->url); + printf(" full_name = %s\n name = '%s'\n", fi->full_name, fi->name); + + fi->parent = parent; + fi->sibling = *fip; + *fip = fi; + g_free(uri); + } + + g_free(tmp); + g_free(cur); + g_free(new); + + /* we only look further if we found one at this level */ + if (fi && ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) || parent == NULL)) { + dir = opendir(name); + if (dir == NULL) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not scan folder `%s': %s"), + root, strerror(errno)); + g_free(name); + return -1; + } + + while ( (d = readdir(dir)) ) { + if (strcmp(d->d_name, "tmp") == 0 + || strcmp(d->d_name, "cur") == 0 + || strcmp(d->d_name, "new") == 0 + || strcmp(d->d_name, ".") == 0 + || strcmp(d->d_name, "..") == 0) + continue; + + tmp = g_strdup_printf("%s/%s", name, d->d_name); + if (stat(tmp, &st) == 0 && S_ISDIR(st.st_mode)) { + new = g_strdup_printf("%s/%s", path, d->d_name); + if (scan_dir(root, new, flags, fi, &fi->child, ex) == -1) { + g_free(tmp); + g_free(new); + closedir(dir); + return -1; + } + g_free(new); + } + g_free(tmp); + } + closedir(dir); + } + + g_free(name); + + return 0; +} + +static CamelFolderInfo * +get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex) +{ + CamelFolderInfo *fi = NULL; + CamelService *service = (CamelService *)store; + + if (scan_dir(service->url->path, top?top:".", flags, NULL, &fi, ex) == -1 && fi != NULL) { + camel_store_free_folder_info_full(store, fi); + fi = NULL; + } + + return fi; +} diff --git a/camel/providers/local/camel-spool-folder.c b/camel/providers/local/camel-spool-folder.c index 0df6fae026..acbdb8d1e7 100644 --- a/camel/providers/local/camel-spool-folder.c +++ b/camel/providers/local/camel-spool-folder.c @@ -44,6 +44,8 @@ #include "camel-mime-filter-from.h" #include "camel-exception.h" +#include "camel-lock-client.h" + #include "camel-local-private.h" #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/ @@ -187,22 +189,25 @@ camel_spool_folder_construct(CamelSpoolFolder *lf, CamelStore *parent_store, con root_dir_path = camel_spool_store_get_toplevel_dir(CAMEL_SPOOL_STORE(folder->parent_store)); lf->base_path = g_strdup(root_dir_path); - lf->folder_path = g_strdup_printf("%s/%s", root_dir_path, full_name); + lf->folder_path = g_strdup(root_dir_path); lf->changes = camel_folder_change_info_new(); lf->flags = flags; folder->summary = (CamelFolderSummary *)camel_spool_summary_new(lf->folder_path); - if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) != -1) { - camel_spool_summary_check((CamelSpoolSummary *)folder->summary, NULL, ex); - camel_spool_folder_unlock(lf); + if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) == -1) { + camel_object_unref((CamelObject *)lf); + return NULL; } + camel_spool_summary_check((CamelSpoolSummary *)folder->summary, NULL, ex); + camel_spool_folder_unlock(lf); + fi = g_malloc0(sizeof(*fi)); fi->full_name = g_strdup(full_name); fi->name = g_strdup(name); fi->url = g_strdup(lf->folder_path); - fi->unread_message_count = -1; + fi->unread_message_count = camel_folder_get_unread_message_count(folder); camel_object_trigger_event(CAMEL_OBJECT(parent_store), "folder_created", fi); camel_folder_info_free (fi); @@ -256,13 +261,44 @@ int camel_spool_folder_unlock(CamelSpoolFolder *lf) static int spool_lock(CamelSpoolFolder *lf, CamelLockType type, CamelException *ex) { - return 0; + int retry = 0; + + lf->lockfd = open(lf->folder_path, O_RDWR, 0); + if (lf->lockfd == -1) { + camel_exception_setv(ex, 1, _("Cannot create folder lock on %s: %s"), lf->folder_path, strerror(errno)); + return -1; + } + + while (retry < CAMEL_LOCK_RETRY) { + if (retry > 0) + sleep(CAMEL_LOCK_DELAY); + + camel_exception_clear(ex); + + if (camel_lock_fcntl(lf->lockfd, type, ex) == 0) { + if (camel_lock_flock(lf->lockfd, type, ex) == 0) { + if ((lf->lockid = camel_lock_helper_lock(lf->folder_path, ex)) != -1) + return 0; + camel_unlock_flock(lf->lockfd); + } + camel_unlock_fcntl(lf->lockfd); + } + retry++; + } + + return -1; } static void spool_unlock(CamelSpoolFolder *lf) { - /* nothing */ + camel_lock_helper_unlock(lf->lockid); + lf->lockid = -1; + camel_unlock_flock(lf->lockid); + camel_unlock_fcntl(lf->lockid); + + close(lf->lockfd); + lf->lockfd = -1; } static void @@ -479,10 +515,14 @@ spool_get_message(CamelFolder *folder, const gchar * uid, CamelException *ex) d(printf("Getting message %s\n", uid)); - /* lock the folder first, burn if we can't */ - if (camel_spool_folder_lock(lf, CAMEL_LOCK_READ, ex) == -1) + /* lock the folder first, burn if we can't, need write lock for summary check */ + if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) == -1) return NULL; - + + /* check for new messages, this may renumber uid's though */ + if (camel_spool_summary_check((CamelSpoolSummary *)folder->summary, lf->changes, ex) == -1) + return NULL; + retry: /* get the message summary info */ info = (CamelSpoolMessageInfo *) camel_folder_summary_uid(folder->summary, uid); diff --git a/camel/providers/local/camel-spool-folder.h b/camel/providers/local/camel-spool-folder.h index 87b8c16b0d..2b09802678 100644 --- a/camel/providers/local/camel-spool-folder.h +++ b/camel/providers/local/camel-spool-folder.h @@ -49,6 +49,8 @@ typedef struct { int locked; /* lock counter */ CamelLockType locktype; /* what type of lock we have */ + int lockfd; /* lock fd used for fcntl/etc locking */ + int lockid; /* lock id for dot locking */ char *base_path; /* base path of the spool folder */ char *folder_path; /* the path to the folder itself */ diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c index 5ef47347d1..655050c5f4 100644 --- a/camel/providers/local/camel-spool-store.c +++ b/camel/providers/local/camel-spool-store.c @@ -46,8 +46,9 @@ static CamelFolder *get_folder(CamelStore * store, const char *folder_name, guin static char *get_name(CamelService *service, gboolean brief); static CamelFolder *get_inbox (CamelStore *store, CamelException *ex); static void rename_folder(CamelStore *store, const char *old_name, const char *new_name, CamelException *ex); -static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top, - guint32 flags, CamelException *ex); +static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex); +static void free_folder_info (CamelStore *store, CamelFolderInfo *fi); + 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); @@ -67,7 +68,7 @@ camel_spool_store_class_init (CamelSpoolStoreClass *camel_spool_store_class) camel_store_class->get_folder = get_folder; camel_store_class->get_inbox = get_inbox; camel_store_class->get_folder_info = get_folder_info; - camel_store_class->free_folder_info = camel_store_free_folder_info_full; + camel_store_class->free_folder_info = free_folder_info; camel_store_class->delete_folder = delete_folder; camel_store_class->rename_folder = rename_folder; @@ -95,15 +96,42 @@ static void construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex) { int len; + char *path, *name; + struct stat st; + + printf("constructing store of type %s '%s:%s'\n", + camel_type_to_name(((CamelObject *)service)->s.type), url->protocol, url->path); CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex); if (camel_exception_is_set (ex)) return; + if (service->url->path[0] != '/') { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Store root %s is not an absolute path"), service->url->path); + return; + } + len = strlen (service->url->path); - if (service->url->path[len - 1] != '/') { + if (len > 0 && service->url->path[len - 1] == '/') { service->url->path = g_realloc (service->url->path, len + 2); - strcpy (service->url->path + len, "/"); + service->url->path[len-1] = 0; + } + + path = service->url->path; + len = strlen(path); + name = path; +#if 0 + name = alloca(len+1); + strcpy(name, path); + name[len-1] = 0; +#endif + + if (stat(name, &st) == -1 || !S_ISREG(st.st_mode)) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Spool `%s' does not exist or is not a regular file"), + path); + return; } } @@ -119,35 +147,26 @@ camel_spool_store_get_toplevel_dir (CamelSpoolStore *store) static CamelFolder * get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelException * ex) { - struct stat st; char *path = ((CamelService *)store)->url->path; char *name; + int len; - if (path[0] != '/') { - camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Store root %s is not an absolute path"), path); - return NULL; - } - - name = g_strdup_printf("%s%s", CAMEL_SERVICE(store)->url->path, folder_name); + printf("opening folder %s on path %s\n", folder_name, path); - if (stat(name, &st) == -1) { + /* we only support an 'INBOX' */ + if (strcmp(folder_name, "INBOX") != 0) { camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, _("Folder `%s/%s' does not exist."), path, folder_name); - g_free(name); - return NULL; - } 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; } - g_free(name); + len = strlen(path); + name = alloca(len+1); + strcpy(name, path); + name[len-1] = 0; - return camel_spool_folder_new(store, folder_name, flags, ex); + return camel_spool_folder_new(store, name, flags, ex); } static CamelFolder * @@ -171,12 +190,30 @@ static CamelFolderInfo * get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex) { - /* FIXME: This is broken, but it corresponds to what was - * there before. - */ - return NULL; + CamelFolderInfo *fi = NULL; + CamelService *service = (CamelService *)store; + + if (top == NULL || strcmp(top, "/INBOX") == 0) { + /* FIXME: if the folder is opened we could look it up? */ + fi = g_malloc0(sizeof(*fi)); + fi->full_name = "/INBOX"; + fi->name = "INBOX"; + fi->url = g_strdup_printf("spool://%s#%s", service->url->path, fi->name); + fi->unread_message_count = -1; + } + + return fi; } +static void free_folder_info (CamelStore *store, CamelFolderInfo *fi) +{ + if (fi) { + g_free(fi->url); + g_free(fi); + } +} + + /* default implementation, rename all */ static void rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex) diff --git a/camel/providers/local/camel-spool-store.h b/camel/providers/local/camel-spool-store.h index 1b118d4742..d348421e3c 100644 --- a/camel/providers/local/camel-spool-store.h +++ b/camel/providers/local/camel-spool-store.h @@ -40,7 +40,7 @@ extern "C" { typedef struct { CamelStore parent_object; - + } CamelSpoolStore; diff --git a/camel/providers/local/camel-spool-summary.c b/camel/providers/local/camel-spool-summary.c index 594a33d744..5d508f643a 100644 --- a/camel/providers/local/camel-spool-summary.c +++ b/camel/providers/local/camel-spool-summary.c @@ -513,7 +513,7 @@ spool_summary_check(CamelSpoolSummary *cls, CamelFolderChangeInfo *changeinfo, C if (st.st_size != cls->folder_size || st.st_mtime != s->time) { if (cls->folder_size < st.st_size) { /* this will automatically rescan from 0 if there is a problem */ - d(printf("folder grew, attempting to rebuild from %d\n", cls>folder_size)); + d(printf("folder grew, attempting to rebuild from %d\n", cls->folder_size)); ret = summary_update(cls, cls->folder_size, changeinfo, ex); } else { d(printf("folder shrank! rebuilding from start\n")); @@ -538,6 +538,7 @@ spool_summary_check(CamelSpoolSummary *cls, CamelFolderChangeInfo *changeinfo, C /* if we do, then write out the headers using sync_full, etc */ if (work) { + d(printf("Have to add new headers, re-syncing from the start to accomplish this\n")); ret = spool_summary_sync_full(cls, FALSE, changeinfo, ex); if (stat(cls->folder_path, &st) == -1) { @@ -683,7 +684,7 @@ spool_summary_sync_full(CamelSpoolSummary *cls, gboolean expunge, CamelFolderCha g_assert(info); - d(printf("Looking at message %s\n", info->info.uid)); + d(printf("Looking at message %s\n", camel_message_info_uid(info))); /* only need to seek past deleted messages, otherwise we should be at the right spot/state already */ if (lastdel) { @@ -735,7 +736,7 @@ spool_summary_sync_full(CamelSpoolSummary *cls, gboolean expunge, CamelFolderCha } if (info && info->info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV | CAMEL_MESSAGE_FOLDER_FLAGGED)) { - d(printf("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags)); + d(printf("Updating header for %s flags = %08x\n", camel_message_info_uid(info), info->info.flags)); if (camel_mime_parser_step(mp, &buffer, &len) == HSCAN_FROM_END) { g_warning("camel_mime_parser_step failed (2)"); @@ -955,7 +956,7 @@ spool_summary_sync_quick(CamelSpoolSummary *cls, gboolean expunge, CamelFolderCh g_assert(info); - d(printf("Checking message %s %08x\n", info->info.uid, info->info.flags)); + d(printf("Checking message %s %08x\n", camel_message_info_uid(info), info->info.flags)); if ((info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) == 0) { camel_folder_summary_info_free(s, (CamelMessageInfo *)info); @@ -963,7 +964,7 @@ spool_summary_sync_quick(CamelSpoolSummary *cls, gboolean expunge, CamelFolderCh continue; } - d(printf("Updating message %s\n", info->info.uid)); + d(printf("Updating message %s\n", camel_message_info_uid(info))); camel_mime_parser_seek(mp, info->frompos, SEEK_SET); @@ -1125,7 +1126,7 @@ spool_summary_add(CamelSpoolSummary *cls, CamelMimeMessage *msg, const CamelMess mi = camel_folder_summary_add_from_message((CamelFolderSummary *)cls, msg); if (mi) { - d(printf("Added, uid = %s\n", mi->uid)); + d(printf("Added, uid = %s\n", camel_message_info_uid(mi))); if (info) { CamelTag *tag = info->user_tags; CamelFlag *flag = info->user_flags; |