dovecot-2.2: Added file_dotlock_delete_verified() and changed fi...

dovecot at dovecot.org dovecot at dovecot.org
Sun Jun 24 20:48:58 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/a77ad2346cf0
changeset: 14637:a77ad2346cf0
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jun 24 20:48:38 2012 +0300
description:
Added file_dotlock_delete_verified() and changed file_dotlock_delete() to return void.

diffstat:

 src/lib-fs/fs-posix.c                           |   2 +-
 src/lib-index/mail-cache-compress.c             |   4 ++--
 src/lib-index/mail-cache.c                      |   2 +-
 src/lib-index/mail-transaction-log-file.c       |   6 +++---
 src/lib-master/master-instance.c                |  10 +++++-----
 src/lib-storage/index/dbox-common/dbox-file.c   |   2 +-
 src/lib-storage/index/maildir/maildir-uidlist.c |   2 +-
 src/lib-storage/index/mbox/mbox-lock.c          |   4 ++--
 src/lib-storage/list/subscription-file.c        |   4 ++--
 src/lib/file-dotlock.c                          |   7 ++++++-
 src/lib/file-dotlock.h                          |   8 +++++---
 11 files changed, 29 insertions(+), 22 deletions(-)

diffs (219 lines):

diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-fs/fs-posix.c
--- a/src/lib-fs/fs-posix.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-fs/fs-posix.c	Sun Jun 24 20:48:38 2012 +0300
@@ -445,7 +445,7 @@
 	if (lock->file_lock != NULL)
 		file_unlock(&lock->file_lock);
 	if (lock->dotlock != NULL)
-		(void)file_dotlock_delete(&lock->dotlock);
+		file_dotlock_delete(&lock->dotlock);
 	i_free(lock);
 }
 
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-index/mail-cache-compress.c	Sun Jun 24 20:48:38 2012 +0300
@@ -395,13 +395,13 @@
 		   reverse those changes by re-reading them from file. */
 		if (mail_cache_header_fields_read(cache) < 0)
 			return -1;
-		(void)file_dotlock_delete(&dotlock);
+		file_dotlock_delete(&dotlock);
 		return -1;
 	}
 
 	if (fstat(fd, &st) < 0) {
 		mail_cache_set_syscall_error(cache, "fstat()");
-		(void)file_dotlock_delete(&dotlock);
+		file_dotlock_delete(&dotlock);
 		return -1;
 	}
 
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-index/mail-cache.c	Sun Jun 24 20:48:38 2012 +0300
@@ -542,7 +542,7 @@
 	if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK)
 		file_unlock(&cache->file_lock);
 	else
-		(void)file_dotlock_delete(&cache->dotlock);
+		file_dotlock_delete(&cache->dotlock);
 }
 
 static int
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-index/mail-transaction-log-file.c	Sun Jun 24 20:48:38 2012 +0300
@@ -317,7 +317,7 @@
 	if (--file->log->dotlock_count > 0)
 		return 0;
 
-	ret = file_dotlock_delete(&file->log->dotlock);
+	ret = file_dotlock_delete_verified(&file->log->dotlock);
 	if (ret < 0) {
 		log_file_set_syscall_error(file, "file_dotlock_delete()");
 		return -1;
@@ -680,7 +680,7 @@
 							       FALSE) > 0 &&
 			    mail_transaction_log_file_stat(file, FALSE) == 0) {
 				/* yes, it was ok */
-				(void)file_dotlock_delete(dotlock);
+				file_dotlock_delete(dotlock);
 				mail_transaction_log_file_add_to_list(file);
 				return 0;
 			}
@@ -803,7 +803,7 @@
            is for the existing file */
         if (mail_transaction_log_file_create2(file, fd, reset, &dotlock) < 0) {
 		if (dotlock != NULL)
-			(void)file_dotlock_delete(&dotlock);
+			file_dotlock_delete(&dotlock);
 		return -1;
 	}
 	return 0;
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-master/master-instance.c
--- a/src/lib-master/master-instance.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-master/master-instance.c	Sun Jun 24 20:48:38 2012 +0300
@@ -144,7 +144,7 @@
 		return -1;
 	}
 	if (master_instance_list_refresh(list) < 0) {
-		(void)file_dotlock_delete(dotlock_r);
+		file_dotlock_delete(dotlock_r);
 		return -1;
 	}
 	return fd;
@@ -160,12 +160,12 @@
 		ret = master_instance_list_write(list, fd, lock_path);
 	} T_END;
 	if (ret < 0) {
-		(void)file_dotlock_delete(dotlock);
+		file_dotlock_delete(dotlock);
 		return -1;
 	}
 	if (fdatasync(fd) < 0) {
 		i_error("fdatasync(%s) failed: %m", lock_path);
-		(void)file_dotlock_delete(dotlock);
+		file_dotlock_delete(dotlock);
 		return -1;
 	}
 	return file_dotlock_replace(dotlock, 0);
@@ -222,7 +222,7 @@
 	if (orig_inst != NULL &&
 	    strcmp(orig_inst->base_dir, base_dir) != 0) {
 		/* name already used */
-		(void)file_dotlock_delete(&dotlock);
+		file_dotlock_delete(&dotlock);
 		return 0;
 	}
 
@@ -257,7 +257,7 @@
 	}
 
 	if (i == count) {
-		(void)file_dotlock_delete(&dotlock);
+		file_dotlock_delete(&dotlock);
 		return 0;
 	}
 	return master_instance_write_finish(list, fd, &dotlock) < 0 ? -1 : 1;
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/index/dbox-common/dbox-file.c
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Sun Jun 24 20:48:38 2012 +0300
@@ -328,7 +328,7 @@
 #ifdef DBOX_FILE_LOCK_METHOD_FLOCK
 		file_unlock(&file->lock);
 #else
-		(void)file_dotlock_delete(&file->lock);
+		file_dotlock_delete(&file->lock);
 #endif
 	}
 	if (file->input != NULL)
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/index/maildir/maildir-uidlist.c
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Sun Jun 24 20:48:38 2012 +0300
@@ -243,7 +243,7 @@
 		return;
 
 	uidlist->locked_refresh = FALSE;
-	(void)file_dotlock_delete(&uidlist->dotlock);
+	file_dotlock_delete(&uidlist->dotlock);
 }
 
 static bool dotlock_callback(unsigned int secs_left, bool stale, void *context)
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/index/mbox/mbox-lock.c
--- a/src/lib-storage/index/mbox/mbox-lock.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Sun Jun 24 20:48:38 2012 +0300
@@ -315,7 +315,7 @@
 		break;
 	case MBOX_DOTLOCK_OP_UNLOCK:
 		/* we're now privileged - avoid doing as much as possible */
-		ret = file_dotlock_delete(&mbox->mbox_dotlock);
+		ret = file_dotlock_delete_verified(&mbox->mbox_dotlock);
 		if (ret < 0)
 			mbox_set_syscall_error(mbox, "file_dotlock_delete()");
 		mbox->mbox_used_privileges = FALSE;
@@ -391,7 +391,7 @@
 			return 1;
 
 		if (!mbox->mbox_used_privileges) {
-			if (file_dotlock_delete(&mbox->mbox_dotlock) <= 0) {
+			if (file_dotlock_delete_verified(&mbox->mbox_dotlock) <= 0) {
 				mbox_set_syscall_error(mbox,
 						       "file_dotlock_delete()");
 			}
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/list/subscription-file.c
--- a/src/lib-storage/list/subscription-file.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib-storage/list/subscription-file.c	Sun Jun 24 20:48:38 2012 +0300
@@ -132,7 +132,7 @@
 	fd_in = nfs_safe_open(path, O_RDONLY);
 	if (fd_in == -1 && errno != ENOENT) {
 		subswrite_set_syscall_error(list, "open()", path);
-		(void)file_dotlock_delete(&dotlock);
+		file_dotlock_delete(&dotlock);
 		return -1;
 	}
 
@@ -181,7 +181,7 @@
 	o_stream_destroy(&output);
 
 	if (failed || !changed) {
-		if (file_dotlock_delete(&dotlock) < 0) {
+		if (file_dotlock_delete_verified(&dotlock) < 0) {
 			subswrite_set_syscall_error(list,
 				"file_dotlock_delete()", path);
 			failed = TRUE;
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib/file-dotlock.c	Sun Jun 24 20:48:38 2012 +0300
@@ -721,7 +721,12 @@
 	return diff > FILE_DOTLOCK_MAX_STAT_MTIME_DIFF;
 }
 
-int file_dotlock_delete(struct dotlock **dotlock_p)
+void file_dotlock_delete(struct dotlock **dotlock_p)
+{
+	(void)file_dotlock_delete_verified(dotlock_p);
+}
+
+int file_dotlock_delete_verified(struct dotlock **dotlock_p)
 {
 	struct dotlock *dotlock;
 	const char *lock_path;
diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib/file-dotlock.h
--- a/src/lib/file-dotlock.h	Sun Jun 24 20:36:05 2012 +0300
+++ b/src/lib/file-dotlock.h	Sun Jun 24 20:48:38 2012 +0300
@@ -58,9 +58,11 @@
 			enum dotlock_create_flags flags,
 			struct dotlock **dotlock_r);
 
-/* Delete the dotlock file. Returns 1 if successful, 0 if the file was already
-   been deleted or reused by someone else, -1 if error. */
-int file_dotlock_delete(struct dotlock **dotlock);
+/* Delete the dotlock file, ignoring any potential errors. */
+void file_dotlock_delete(struct dotlock **dotlock);
+/* Delete the dotlock file. Returns 1 if successful, 0 if the file had already
+   been deleted or reused by someone else, -1 if I/O error. */
+int file_dotlock_delete_verified(struct dotlock **dotlock);
 
 /* Use dotlock as the new content for file. This provides read safety without
    locks, but it's not very good for large files. Returns fd for lock file.


More information about the dovecot-cvs mailing list