changeset 10543:f20bced53213 HEAD

lib-storage: Removed mailbox_list_get_guid(). Directory GUIDs are pretty pointless.
author Timo Sirainen <tss@iki.fi>
date Thu, 31 Dec 2009 13:46:24 -0500
parents de75c45e6765
children 3c12d0376cef
files 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
diffstat 14 files changed, 15 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-storage.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Thu Dec 31 13:46:24 2009 -0500
@@ -46,8 +46,6 @@
 		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,
--- a/src/lib-storage/index/cydir/cydir-storage.h	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/cydir/cydir-storage.h	Thu Dec 31 13:46:24 2009 -0500
@@ -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;
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Thu Dec 31 13:46:24 2009 -0500
@@ -21,8 +21,6 @@
 		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)
--- a/src/lib-storage/index/dbox-common/dbox-storage.h	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/dbox-common/dbox-storage.h	Thu Dec 31 13:46:24 2009 -0500
@@ -9,7 +9,6 @@
 #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"
--- a/src/lib-storage/index/maildir/maildir-storage.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Thu Dec 31 13:46:24 2009 -0500
@@ -142,8 +142,6 @@
 		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 @@
 {
 	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 @@
 	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;
 }
--- a/src/lib-storage/index/maildir/maildir-storage.h	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Thu Dec 31 13:46:24 2009 -0500
@@ -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> */
--- a/src/lib-storage/index/mbox/mbox-storage.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Thu Dec 31 13:46:24 2009 -0500
@@ -822,20 +822,6 @@
 	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 @@
 	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);
 }
--- a/src/lib-storage/index/mbox/mbox-storage.h	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Thu Dec 31 13:46:24 2009 -0500
@@ -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;
--- a/src/lib-storage/index/shared/shared-list.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/index/shared/shared-list.c	Thu Dec 31 13:46:24 2009 -0500
@@ -325,7 +325,6 @@
 		shared_list_set_subscribed,
 		shared_list_delete_mailbox,
 		shared_list_rename_mailbox,
-		shared_list_rename_mailbox_pre,
-		NULL
+		shared_list_rename_mailbox_pre
 	}
 };
--- a/src/lib-storage/list/mailbox-list-fs.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/list/mailbox-list-fs.c	Thu Dec 31 13:46:24 2009 -0500
@@ -437,7 +437,6 @@
 		fs_list_set_subscribed,
 		fs_list_delete_mailbox,
 		fs_list_rename_mailbox,
-		NULL,
 		NULL
 	}
 };
--- a/src/lib-storage/list/mailbox-list-maildir.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Thu Dec 31 13:46:24 2009 -0500
@@ -462,7 +462,6 @@
 		maildir_list_set_subscribed,
 		maildir_list_delete_mailbox,
 		maildir_list_rename_mailbox,
-		NULL,
 		NULL
 	}
 };
@@ -491,7 +490,6 @@
 		maildir_list_set_subscribed,
 		maildir_list_delete_mailbox,
 		maildir_list_rename_mailbox,
-		NULL,
 		NULL
 	}
 };
--- a/src/lib-storage/mailbox-list-private.h	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/mailbox-list-private.h	Thu Dec 31 13:46:24 2009 -0500
@@ -66,8 +66,6 @@
 				  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 @@
 			     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,
--- a/src/lib-storage/mailbox-list.c	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/mailbox-list.c	Thu Dec 31 13:46:24 2009 -0500
@@ -137,8 +137,6 @@
 	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 @@
 				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 @@
 	   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 @@
 		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])
+void mailbox_name_get_sha128(const char *name, uint8_t 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])
-{
-	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;
-	}
+	unsigned char sha[SHA1_RESULTLEN];
 
-	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;
-
-	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)
--- a/src/lib-storage/mailbox-list.h	Thu Dec 31 15:15:54 2009 -0500
+++ b/src/lib-storage/mailbox-list.h	Thu Dec 31 13:46:24 2009 -0500
@@ -101,7 +101,6 @@
 
 	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 @@
 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.