dovecot-2.0: sdbox: Don't delete attachment file until mail file...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 2 14:34:08 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/c68984eaf277
changeset: 12269:c68984eaf277
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Sep 24 19:50:20 2010 +0100
description:
sdbox: Don't delete attachment file until mail file's link count drops to 0.
This fixes attachments getting deleted too early when messages are copied
with hard linking.

diffstat:

 src/lib-storage/index/dbox-single/sdbox-file.c |  15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diffs (32 lines):

diff -r 8bdb7f50aebe -r c68984eaf277 src/lib-storage/index/dbox-single/sdbox-file.c
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Fri Sep 24 19:40:13 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Fri Sep 24 19:50:20 2010 +0100
@@ -246,6 +246,7 @@
 	ARRAY_TYPE(mail_attachment_extref) extrefs;
 	const struct mail_attachment_extref *extref;
 	const char *line;
+	struct stat st;
 	pool_t pool;
 	bool deleted;
 	int ret;
@@ -280,8 +281,18 @@
 	   missing attachments */
 	if (dbox_file_unlink(file) < 0)
 		ret = -1;
-	else {
-		/* if deleting any attachment fails, we can't do anything else
+	else if (fstat(file->fd, &st) < 0) {
+		mail_storage_set_critical(&storage->storage,
+			"fstat(%s) failed: %m", file->cur_path);
+		ret = -1;
+	} else if (st.st_nlink == 0) {
+		/* the attachments are deleted only after the file's link count
+		   drops to zero. whoever unlinks the last link will delete
+		   the attachments. there's a race condition, but that only
+		   means that multiple processes may attempt to unlink the
+		   attachments at the same time, which is fine.
+
+		   if deleting any attachment fails, we can't do anything else
 		   but ignore it, since the main main mail file is already
 		   deleted */
 		array_foreach(&extrefs, extref) {


More information about the dovecot-cvs mailing list