changeset 7801:40da0a9ccd9d HEAD

Maildir: When hardlink-copying a file, copy the W=vsize if it exists in the original filename.
author Timo Sirainen <tss@iki.fi>
date Mon, 09 Jun 2008 06:04:01 +0300
parents 524b4acad38b
children 64c9fa2d2cae
files src/lib-storage/index/maildir/maildir-copy.c
diffstat 1 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-copy.c	Mon Jun 09 05:55:51 2008 +0300
+++ b/src/lib-storage/index/maildir/maildir-copy.c	Mon Jun 09 06:04:01 2008 +0300
@@ -23,6 +23,7 @@
 	unsigned int base_end_pos;
 
 	unsigned int size_set:1;
+	unsigned int vsize_set:1;
 	unsigned int success:1;
 	unsigned int preserve_filename:1;
 };
@@ -49,7 +50,7 @@
 		size = st.st_size;
 	}
 
-	str = t_strdup_printf(",S=%"PRIuUOFF_T, size);
+	str = t_strdup_printf(",%c=%"PRIuUOFF_T, MAILDIR_EXTRA_FILE_SIZE, size);
 	str_insert(ctx->dest_path, ctx->base_end_pos, str);
 
 	ctx->dest_fname = strrchr(str_c(ctx->dest_path), '/') + 1;
@@ -57,15 +58,40 @@
 	return 1;
 }
 
+static void do_save_mail_vsize(const char *path, struct hardlink_ctx *ctx)
+{
+	const char *fname, *str;
+	uoff_t size;
+
+	fname = strrchr(path, '/');
+	fname = fname != NULL ? fname + 1 : path;
+
+	if (!maildir_filename_get_size(fname, MAILDIR_EXTRA_VIRTUAL_SIZE,
+				       &size))
+		return;
+
+	str = t_strdup_printf(",%c=%"PRIuUOFF_T,
+			      MAILDIR_EXTRA_VIRTUAL_SIZE, size);
+	str_insert(ctx->dest_path, ctx->base_end_pos, str);
+
+	ctx->dest_fname = strrchr(str_c(ctx->dest_path), '/') + 1;
+	ctx->vsize_set = TRUE;
+}
+
 static int do_hardlink(struct maildir_mailbox *mbox, const char *path,
 		       struct hardlink_ctx *ctx)
 {
 	int ret;
 
-	if (!ctx->preserve_filename && mbox->storage->save_size_in_filename &&
-	    !ctx->size_set) {
-		if ((ret = do_save_mail_size(mbox, path, ctx)) <= 0)
-			return ret;
+	if (!ctx->preserve_filename) {
+		if (mbox->storage->save_size_in_filename &&
+		    !ctx->size_set) {
+			if ((ret = do_save_mail_size(mbox, path, ctx)) <= 0)
+				return ret;
+		}
+		/* set virtual size if it's in the original file name */
+		if (!ctx->vsize_set)
+			do_save_mail_vsize(path, ctx);
 	}
 
 	if ((mbox->storage->storage.flags &