]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Removed mailbox_list_get_guid().
authorTimo Sirainen <tss@iki.fi>
Thu, 31 Dec 2009 18:46:24 +0000 (13:46 -0500)
committerTimo Sirainen <tss@iki.fi>
Thu, 31 Dec 2009 18:46:24 +0000 (13:46 -0500)
Directory GUIDs are pretty pointless.

--HG--
branch : HEAD

14 files changed:
src/lib-storage/index/cydir/cydir-storage.c
src/lib-storage/index/cydir/cydir-storage.h
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-common/dbox-storage.h
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/maildir/maildir-storage.h
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/mbox/mbox-storage.h
src/lib-storage/index/shared/shared-list.c
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mailbox-list-private.h
src/lib-storage/mailbox-list.c
src/lib-storage/mailbox-list.h

index 3065c997cd477a0223c1250c378617d04f645d8d..7bec3a304ae68714bffd4adcbb0a3d140df98ef2 100644 (file)
@@ -46,8 +46,6 @@ cydir_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
                set->layout = MAILBOX_LIST_NAME_FS;
        if (set->subscription_fname == NULL)
                set->subscription_fname = CYDIR_SUBSCRIPTION_FILE_NAME;
-       if (set->dir_guid_fname == NULL)
-               set->dir_guid_fname = CYDIR_DIR_GUID_FILE_NAME;
 }
 
 static int create_cydir(struct mail_storage *storage, struct mailbox_list *list,
index 682740a42833e2315ecfa743863b91f6324127fb..329fdab162f9ee6750b71e96cdd087f2763f891c 100644 (file)
@@ -7,7 +7,6 @@
 #define CYDIR_STORAGE_NAME "cydir"
 #define CYDIR_SUBSCRIPTION_FILE_NAME "subscriptions."
 #define CYDIR_INDEX_PREFIX "dovecot.index"
-#define CYDIR_DIR_GUID_FILE_NAME "dovecot.dir.guid."
 
 struct cydir_storage {
        struct mail_storage storage;
index 93794c61b7aaf296a86686102c21ca38b75b88cd..d5e7bfb194257183991c5f2c7f8cdca0da63d703 100644 (file)
@@ -21,8 +21,6 @@ void dbox_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
                set->layout = MAILBOX_LIST_NAME_FS;
        if (set->subscription_fname == NULL)
                set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
-       if (set->dir_guid_fname == NULL)
-               set->dir_guid_fname = DBOX_DIR_GUID_FILE_NAME;
        if (set->maildir_name == NULL)
                set->maildir_name = DBOX_MAILDIR_NAME;
        if (set->mailbox_dir_name == NULL)
index 97e7d61e8ffae910d3ae0154d794096aba5e71c5..0d3248833aeb9868d3a70c345bb625c327c9510b 100644 (file)
@@ -9,7 +9,6 @@ struct dbox_mail;
 #define DBOX_SUBSCRIPTION_FILE_NAME "subscriptions"
 #define DBOX_UIDVALIDITY_FILE_NAME "dovecot-uidvalidity"
 #define DBOX_INDEX_PREFIX "dovecot.index"
-#define DBOX_DIR_GUID_FILE_NAME "dbox-GUID"
 
 #define DBOX_MAILBOX_DIR_NAME "mailboxes"
 #define DBOX_TRASH_DIR_NAME "trash"
index 353dd98871d2b24d4e82c4f0717fa0687494dd13..3ca5cfd505e278ce756570ff5356ed6dc909bd4b 100644 (file)
@@ -142,8 +142,6 @@ static void maildir_storage_get_list_settings(const struct mail_namespace *ns,
                set->layout = MAILBOX_LIST_NAME_MAILDIRPLUSPLUS;
        if (set->subscription_fname == NULL)
                set->subscription_fname = MAILDIR_SUBSCRIPTION_FILE_NAME;
-       if (set->dir_guid_fname == NULL)
-               set->dir_guid_fname = MAILDIR_DIR_GUID_FILE_NAME;
 
        if (set->inbox_path == NULL &&
            (strcmp(set->layout, MAILBOX_LIST_NAME_MAILDIRPLUSPLUS) == 0 ||
@@ -783,13 +781,12 @@ maildir_list_delete_mailbox(struct mailbox_list *list, const char *name)
 {
        union mailbox_list_module_context *mlist = MAILDIR_LIST_CONTEXT(list);
        uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
-       uint8_t dir_guid[MAIL_GUID_128_SIZE];
+       uint8_t dir_sha128[MAIL_GUID_128_SIZE];
        struct stat st;
        const char *src, *dest, *base;
        int ret;
 
        mailbox_get_guid(list, name, mailbox_guid);
-       (void)mailbox_list_get_guid(list, name, dir_guid);
 
        /* Make sure the indexes are closed before trying to delete the
           directory that contains them. It can still fail with some NFS
@@ -844,8 +841,9 @@ maildir_list_delete_mailbox(struct mailbox_list *list, const char *name)
        if (ret == 0) {
                mailbox_list_add_change(list, MAILBOX_LOG_RECORD_DELETE_MAILBOX,
                                        mailbox_guid);
+               mailbox_name_get_sha128(name, dir_sha128);
                mailbox_list_add_change(list, MAILBOX_LOG_RECORD_DELETE_DIR,
-                                       dir_guid);
+                                       dir_sha128);
        }
        return 0;
 }
index 93afb6528ae1564f790c3d284c7ff723f00c26f3..7382e91a397f8382530a8bbd313cb7420f3e25bf 100644 (file)
@@ -8,7 +8,6 @@
 #define MAILDIR_INDEX_PREFIX "dovecot.index"
 #define MAILDIR_UNLINK_DIRNAME "DOVECOT-TRASHED"
 #define MAILDIR_UIDVALIDITY_FNAME "dovecot-uidvalidity"
-#define MAILDIR_DIR_GUID_FILE_NAME "dovecot-dir-guid"
 
 /* "base,S=123:2," means:
    <base> [<extra sep> <extra data> [..]] <info sep> 2 <flags sep> */
index ef6ba48a5bdaf1ab7a101ec2dceeac50e461689f..7708309e995d6bb871e84ca19ded3d08591bef81 100644 (file)
@@ -822,20 +822,6 @@ static int mbox_list_delete_mailbox(struct mailbox_list *list,
        return 0;
 }
 
-static int mbox_get_guid(struct mailbox_list *list, const char *name,
-                        uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
-{
-       const char *dir, *path;
-
-       memset(mailbox_guid, 0, MAIL_GUID_128_SIZE);
-       dir = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_INDEX);
-       if (index_list_create_missing_index_dir(list, name) < 0)
-               return -1;
-       path = t_strconcat(dir, "/"MBOX_DIR_GUID_FILE_NAME, NULL);
-
-       return mailbox_list_get_guid_path(list, path, mailbox_guid);
-}
-
 static void mbox_storage_add_list(struct mail_storage *storage,
                                  struct mailbox_list *list)
 {
@@ -854,7 +840,6 @@ static void mbox_storage_add_list(struct mail_storage *storage,
        list->v.delete_mailbox = mbox_list_delete_mailbox;
        list->v.is_valid_existing_name = mbox_is_valid_existing_name;
        list->v.is_valid_create_name = mbox_is_valid_create_name;
-       list->v.get_guid = mbox_get_guid;
 
        MODULE_CONTEXT_SET(list, mbox_mailbox_list_module, mlist);
 }
index b1c25cca3c98d69a4b6466e1dcc18a99c677bfab..ccf096ff6100245c5a83d2f1aae836a224227c31 100644 (file)
@@ -14,7 +14,6 @@
 #define MBOX_SUBSCRIPTION_FILE_NAME ".subscriptions"
 #define MBOX_INDEX_PREFIX "dovecot.index"
 #define MBOX_INDEX_DIR_NAME ".imap"
-#define MBOX_DIR_GUID_FILE_NAME "dovecot-dir-guid"
 
 struct mbox_index_header {
        uint64_t sync_size;
index 35f57ba8f14edbb65187905aa613a0f6a757de7f..f900a758cae885f161a22e616d0604ac7331a46b 100644 (file)
@@ -325,7 +325,6 @@ struct mailbox_list shared_mailbox_list = {
                shared_list_set_subscribed,
                shared_list_delete_mailbox,
                shared_list_rename_mailbox,
-               shared_list_rename_mailbox_pre,
-               NULL
+               shared_list_rename_mailbox_pre
        }
 };
index c0f1eecd1c47f760dd04e59976118999bd680d37..67d889ae51ec1b2889121662c94a9e8c7d66e6f4 100644 (file)
@@ -437,7 +437,6 @@ struct mailbox_list fs_mailbox_list = {
                fs_list_set_subscribed,
                fs_list_delete_mailbox,
                fs_list_rename_mailbox,
-               NULL,
                NULL
        }
 };
index b5bcb62c2322cd48111e372b61e0987ec849b745..6734d4df6210f6561ee6e92fca68458e07b493a5 100644 (file)
@@ -462,7 +462,6 @@ struct mailbox_list maildir_mailbox_list = {
                maildir_list_set_subscribed,
                maildir_list_delete_mailbox,
                maildir_list_rename_mailbox,
-               NULL,
                NULL
        }
 };
@@ -491,7 +490,6 @@ struct mailbox_list imapdir_mailbox_list = {
                maildir_list_set_subscribed,
                maildir_list_delete_mailbox,
                maildir_list_rename_mailbox,
-               NULL,
                NULL
        }
 };
index fb7107fe8f0f47737c6a698106484f8c7db16bcb..9e0bf1f442afd8b59ecc7c8531e5d84e8a6eaef4 100644 (file)
@@ -66,8 +66,6 @@ struct mailbox_list_vfuncs {
                                  const char *oldname,
                                  struct mailbox_list *newlist,
                                  const char *newname);
-       int (*get_guid)(struct mailbox_list *list, const char *name,
-                       uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
 };
 
 struct mailbox_list_module_register {
@@ -155,6 +153,8 @@ void mailbox_list_add_change(struct mailbox_list *list,
                             const uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
 int mailbox_list_get_guid_path(struct mailbox_list *list, const char *path,
                               uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
+void mailbox_name_get_sha128(const char *name,
+                            uint8_t guid[MAIL_GUID_128_SIZE]);
 
 void mailbox_list_clear_error(struct mailbox_list *list);
 void mailbox_list_set_error(struct mailbox_list *list,
index cab441bdde5931fbb7dc6671273c88cf88a67769..d7053778d7002ff1facd3c4de26b505943fd7187 100644 (file)
@@ -137,8 +137,6 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
        list->set.inbox_path = p_strdup(list->pool, set->inbox_path);
        list->set.subscription_fname =
                p_strdup(list->pool, set->subscription_fname);
-       list->set.dir_guid_fname =
-               p_strdup(list->pool, set->dir_guid_fname);
        list->set.maildir_name = set->maildir_name == NULL ||
                (list->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 ? "" :
                p_strdup(list->pool, set->maildir_name);
@@ -718,7 +716,6 @@ int mailbox_list_set_subscribed(struct mailbox_list *list,
                                const char *name, bool set)
 {
        uint8_t guid[MAIL_GUID_128_SIZE];
-       unsigned char sha[SHA1_RESULTLEN];
 
        if (list->v.set_subscribed(list, name, set) < 0)
                return -1;
@@ -727,8 +724,7 @@ int mailbox_list_set_subscribed(struct mailbox_list *list,
           to have a subscription to non-existing mailbox. renames also don't
           change subscriptions. so instead of using actual GUIDs, we'll use
           hash of the name. */
-       sha1_get_digest(name, strlen(name), sha);
-       memcpy(guid, sha, I_MIN(sizeof(guid), sizeof(sha)));
+       mailbox_name_get_sha128(name, guid);
        mailbox_list_add_change(list, set ? MAILBOX_LOG_RECORD_SUBSCRIBE :
                                MAILBOX_LOG_RECORD_UNSUBSCRIBE, guid);
        return 0;
@@ -795,125 +791,23 @@ int mailbox_list_rename_mailbox(struct mailbox_list *oldlist,
                return -1;
        }
 
-       (void)mailbox_list_get_guid(oldlist, oldname, guid);
        if (oldlist->v.rename_mailbox(oldlist, oldname, newlist, newname,
                                      rename_children) < 0)
                return -1;
+
+       /* we'll track mailbox names, instead of GUIDs. We may be renaming a
+          non-selectable mailbox (directory), which doesn't even have a GUID */
+       mailbox_name_get_sha128(newname, guid);
        mailbox_list_add_change(oldlist, MAILBOX_LOG_RECORD_RENAME, guid);
        return 0;
 }
 
-static int mailbox_list_read_guid(struct mailbox_list *list, const char *path,
-                                 uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
-{
-       int fd, ret;
-
-       fd = open(path, O_RDONLY);
-       if (fd != -1) {
-               ret = read_full(fd, mailbox_guid, MAIL_GUID_128_SIZE);
-               close_keep_errno(fd);
-               if (ret > 0)
-                       return 1;
-               if (ret < 0) {
-                       mailbox_list_set_critical(list, "read(%s) failed: %m",
-                                                 path);
-                       return -1;
-               }
-               /* recreate it */
-               mailbox_list_set_critical(list, "Corrupted mailbox GUID in %s",
-                                         path);
-               (void)unlink(path);
-               return 0;
-       } else if (errno == ENOENT) {
-               return 0;
-       } else if (errno == EACCES) {
-               mailbox_list_set_critical(list, "%s",
-                                         eacces_error_get("open", path));
-               return -1;
-       } else {
-               mailbox_list_set_critical(list, "open(%s) failed: %m", path);
-               return -1;
-       }
-}
-
-int mailbox_list_get_guid_path(struct mailbox_list *list, const char *path,
-                              uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
+void mailbox_name_get_sha128(const char *name, uint8_t guid[MAIL_GUID_128_SIZE])
 {
-       string_t *temp_path;
-       int fd, ret;
-
-       /* try reading the GUID from the file */
-       if ((ret = mailbox_list_read_guid(list, path, mailbox_guid)) < 0)
-               return -1;
-
-       /* create temp file containing a new GUID. the file must never be
-          modified and it doesn't contain anything sensitive, so just make
-          it world-readable. */
-       temp_path = t_str_new(256);
-       str_append(temp_path, path);
-       fd = safe_mkstemp_hostpid_group(temp_path, 0644, (gid_t)-1, NULL);
-       if (fd == -1) {
-               mailbox_list_set_critical(list,
-                       "safe_mkstemp(%s) failed: %m", str_c(temp_path));
-               return -1;
-       }
-
-       mail_generate_guid_128(mailbox_guid);
-       ret = write_full(fd, mailbox_guid, MAIL_GUID_128_SIZE);
-       close_keep_errno(fd);
-       if (ret < 0) {
-               mailbox_list_set_critical(list,
-                       "write(%s) failed: %m", str_c(temp_path));
-       } else if (link(str_c(temp_path), path) == 0) {
-               /* success */
-       } else if (errno == EEXIST) {
-               /* someone else just created the GUID, read it. */
-               ret = mailbox_list_read_guid(list, path, mailbox_guid);
-               if (ret == 0) {
-                       /* broken? shouldn't really happen. we anyway deleted
-                          it already, so try again. */
-                       return mailbox_list_get_guid_path(list, path,
-                                                         mailbox_guid);
-               }
-       } else {
-               mailbox_list_set_critical(list, "link(%s, %s) failed: %m",
-                                         str_c(temp_path), path);
-               ret = -1;
-       }
-       (void)unlink(str_c(temp_path));
-       return ret < 0 ? -1 : 0;
-}
-
-static int
-mailbox_list_get_guid_default(struct mailbox_list *list, const char *name,
-                             uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
-{
-       const char *dir, *path;
-
-       memset(mailbox_guid, 0, MAIL_GUID_128_SIZE);
-       if (list->set.dir_guid_fname == NULL) {
-               mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
-                       "Storage doesn't support mailbox GUIDs");
-               return -1;
-       }
-
-       dir = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_DIR);
-       path = t_strconcat(dir, "/", list->set.dir_guid_fname, NULL);
-
-       return mailbox_list_get_guid_path(list, path, mailbox_guid);
-}
-
-int mailbox_list_get_guid(struct mailbox_list *list, const char *name,
-                         uint8_t mailbox_guid[MAIL_GUID_128_SIZE])
-{
-       int ret;
+       unsigned char sha[SHA1_RESULTLEN];
 
-       T_BEGIN {
-               ret = list->v.get_guid != NULL ?
-                       list->v.get_guid(list, name, mailbox_guid) :
-                       mailbox_list_get_guid_default(list, name, mailbox_guid);
-       } T_END;
-       return ret;
+       sha1_get_digest(name, strlen(name), sha);
+       memcpy(guid, sha, I_MIN(sizeof(guid), sizeof(sha)));
 }
 
 struct mailbox_log *mailbox_list_get_changelog(struct mailbox_list *list)
index 7f2335759cfbf6aa7013af410f2db979ff4ea8b9..7fb36a0128a3a9b8bd9c4473ee7929a1580f0cc9 100644 (file)
@@ -101,7 +101,6 @@ struct mailbox_list_settings {
 
        const char *inbox_path;
        const char *subscription_fname;
-       const char *dir_guid_fname;
        /* If non-empty, it means that mails exist in a maildir_name
           subdirectory. eg. if you have a directory containing directories:
 
@@ -189,9 +188,6 @@ const char *mailbox_list_get_path(struct mailbox_list *list, const char *name,
 int mailbox_list_get_mailbox_name_status(struct mailbox_list *list,
                                         const char *name,
                                         enum mailbox_name_status *status);
-/* Get 128bit mailbox directory GUID, creating it if necessary. */
-int mailbox_list_get_guid(struct mailbox_list *list, const char *name,
-                         uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
 /* Returns mailbox's change log, or NULL if it doesn't have one. */
 struct mailbox_log *mailbox_list_get_changelog(struct mailbox_list *list);
 /* Specify timestamp to use when writing mailbox changes to changelog.