dovecot-2.0: dbox: Don't write save-date to metadata, use file's...

dovecot at dovecot.org dovecot at dovecot.org
Sun Mar 21 17:08:53 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/cc42255736ad
changeset: 10964:cc42255736ad
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Mar 21 17:08:36 2010 +0200
description:
dbox: Don't write save-date to metadata, use file's ctime as fallback.
Copying must change the save-date, so it couldn't work well in metadata.

diffstat:

 src/lib-storage/index/dbox-common/dbox-file.c  |  36 ++++++++++++++++++
 src/lib-storage/index/dbox-common/dbox-file.h  |   7 ++-
 src/lib-storage/index/dbox-common/dbox-mail.c  |  22 ++--------
 src/lib-storage/index/dbox-common/dbox-save.c  |   2 -
 src/lib-storage/index/dbox-single/sdbox-save.c |   8 ++++
 5 files changed, 54 insertions(+), 21 deletions(-)

diffs (145 lines):

diff -r d87741f0e95a -r cc42255736ad src/lib-storage/index/dbox-common/dbox-file.c
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Sun Mar 21 16:50:11 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Sun Mar 21 17:08:36 2010 +0200
@@ -219,6 +219,42 @@
 	return dbox_file_open_full(file, FALSE, notfound_r);
 }
 
+int dbox_file_stat(struct dbox_file *file, struct stat *st_r)
+{
+	const char *path;
+	bool alt = FALSE;
+
+	if (dbox_file_is_open(file)) {
+		if (fstat(file->fd, st_r) < 0) {
+			mail_storage_set_critical(&file->storage->storage,
+				"fstat(%s) failed: %m", file->cur_path);
+			return -1;
+		}
+		return 0;
+	}
+
+	/* try the primary path first */
+	path = file->primary_path;
+	while (stat(path, st_r) < 0) {
+		if (errno != ENOENT) {
+			mail_storage_set_critical(&file->storage->storage,
+						  "stat(%s) failed: %m", path);
+			return -1;
+		}
+
+		if (file->alt_path == NULL || alt) {
+			/* not found */
+			return -1;
+		}
+
+		/* try the alternative path */
+		path = file->alt_path;
+		alt = TRUE;
+	}
+	file->cur_path = path;
+	return 0;
+}
+
 int dbox_file_header_write(struct dbox_file *file, struct ostream *output)
 {
 	string_t *hdr;
diff -r d87741f0e95a -r cc42255736ad src/lib-storage/index/dbox-common/dbox-file.h
--- a/src/lib-storage/index/dbox-common/dbox-file.h	Sun Mar 21 16:50:11 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-file.h	Sun Mar 21 17:08:36 2010 +0200
@@ -39,8 +39,6 @@
 	DBOX_METADATA_POP3_UIDL		= 'P',
 	/* Received UNIX timestamp in hex */
 	DBOX_METADATA_RECEIVED_TIME	= 'R',
-	/* Saved UNIX timestamp in hex */
-	DBOX_METADATA_SAVE_TIME		= 'S',
 	/* Physical message size in hex. Necessary only if it differs from
 	   the dbox_message_header.message_size_hex, for example because the
 	   message is compressed. */
@@ -59,6 +57,7 @@
 	DBOX_METADATA_OLDV1_EXPUNGED	= 'E',
 	DBOX_METADATA_OLDV1_FLAGS	= 'F',
 	DBOX_METADATA_OLDV1_KEYWORDS	= 'K',
+	DBOX_METADATA_OLDV1_SAVE_TIME	= 'S',
 	DBOX_METADATA_OLDV1_SPACE	= ' '
 };
 
@@ -134,6 +133,10 @@
 /* Close the file handle from the file, but don't free it. */
 void dbox_file_close(struct dbox_file *file);
 
+/* fstat() or stat() the file. If file is already deleted, fails with
+   errno=ENOENT. */
+int dbox_file_stat(struct dbox_file *file, struct stat *st_r);
+
 /* Try to lock the dbox file. Returns 1 if ok, 0 if already locked by someone
    else, -1 if error. */
 int dbox_file_try_lock(struct dbox_file *file);
diff -r d87741f0e95a -r cc42255736ad src/lib-storage/index/dbox-common/dbox-mail.c
--- a/src/lib-storage/index/dbox-common/dbox-mail.c	Sun Mar 21 16:50:11 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-mail.c	Sun Mar 21 17:08:36 2010 +0200
@@ -140,29 +140,17 @@
 	struct index_mail_data *data = &mail->imail.data;
 	struct dbox_file *file;
 	struct stat st;
-	const char *value;
 
  	if (index_mail_get_save_date(_mail, date_r) == 0)
 		return 0;
 
-	if (dbox_mail_metadata_read(mail, &file) < 0)
+	mail->imail.mail.stats_fstat_lookup_count++;
+	if (dbox_file_stat(file, &st) < 0) {
+		if (errno == ENOENT)
+			mail_set_expunged(_mail);
 		return -1;
-
-	value = dbox_file_metadata_get(file, DBOX_METADATA_SAVE_TIME);
-	data->save_date = value == NULL ? 0 : strtoul(value, NULL, 16);
-
-	if (data->save_date == 0) {
-		/* missing / corrupted save time - use the file's ctime */
-		i_assert(dbox_file_is_open(file));
-		mail->imail.mail.stats_fstat_lookup_count++;
-		if (fstat(file->fd, &st) < 0) {
-			mail_storage_set_critical(_mail->box->storage,
-				"fstat(%s) failed: %m", file->cur_path);
-			return -1;
-		}
-		data->save_date = st.st_ctime;
 	}
-	*date_r = data->save_date;
+	*date_r = data->save_date = st.st_ctime;
 	return 0;
 }
 
diff -r d87741f0e95a -r cc42255736ad src/lib-storage/index/dbox-common/dbox-save.c
--- a/src/lib-storage/index/dbox-common/dbox-save.c	Sun Mar 21 16:50:11 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-save.c	Sun Mar 21 17:08:36 2010 +0200
@@ -125,8 +125,6 @@
 	}
 	str_printfa(str, "%c%lx\n", DBOX_METADATA_RECEIVED_TIME,
 		    (unsigned long)ctx->received_date);
-	str_printfa(str, "%c%lx\n", DBOX_METADATA_SAVE_TIME,
-		    (unsigned long)ioloop_time);
 	if (mail_get_virtual_size(ctx->dest_mail, &vsize) < 0)
 		i_unreached();
 	str_printfa(str, "%c%llx\n", DBOX_METADATA_VIRTUAL_SIZE,
diff -r d87741f0e95a -r cc42255736ad src/lib-storage/index/dbox-single/sdbox-save.c
--- a/src/lib-storage/index/dbox-single/sdbox-save.c	Sun Mar 21 16:50:11 2010 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-save.c	Sun Mar 21 17:08:36 2010 +0200
@@ -129,6 +129,14 @@
 	if (ctx->ctx.dbox_output == NULL)
 		return -1;
 
+	if (_ctx->save_date != (time_t)-1) {
+		/* we can't change ctime, but we can add the date to cache */
+		struct index_mail *mail = (struct index_mail *)_ctx->dest_mail;
+		uint32_t t = _ctx->save_date;
+
+		index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
+	}
+
 	index_mail_cache_parse_deinit(_ctx->dest_mail,
 				      _ctx->received_date, !ctx->ctx.failed);
 


More information about the dovecot-cvs mailing list