[dovecot-cvs] dovecot/src/lib-index mail-transaction-log.c, 1.120, 1.121

tss at dovecot.org tss at dovecot.org
Wed Jan 17 18:53:29 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv32639

Modified Files:
	mail-transaction-log.c 
Log Message:
Don't rename() .log to .log.2, because it temporarily loses the log file.
Use unlink() + link() instead.



Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- mail-transaction-log.c	17 Jan 2007 16:17:42 -0000	1.120
+++ mail-transaction-log.c	17 Jan 2007 18:53:27 -0000	1.121
@@ -554,9 +554,19 @@
 
 	/* keep two log files */
 	if (rename_existing) {
+		/* rename() would be nice and easy way to do this, except then
+		   there's a race condition between the rename and
+		   file_dotlock_replace(). during that time the log file
+		   doesn't exist, which could cause problems. */
 		path2 = t_strconcat(file->filepath, ".2", NULL);
-		if (rename(file->filepath, path2) < 0 && errno != ENOENT) {
-                        mail_index_set_error(index, "rename(%s, %s) failed: %m",
+		if (unlink(path2) < 0 && errno != ENOENT) {
+                        mail_index_set_error(index, "unlink(%s) failed: %m",
+					     path2);
+			/* try to link() anyway */
+		}
+		if (link(file->filepath, path2) < 0 &&
+		    errno != ENOENT && errno != EEXIST) {
+                        mail_index_set_error(index, "link(%s, %s) failed: %m",
 					     file->filepath, path2);
 			/* ignore the error. we don't care that much about the
 			   second log file and we're going to overwrite this



More information about the dovecot-cvs mailing list