changeset 5021:623ed4a5339b HEAD

Don't rename() .log to .log.2, because it temporarily loses the log file. Use unlink() + link() instead.
author Timo Sirainen <tss@iki.fi>
date Wed, 17 Jan 2007 20:53:27 +0200
parents ac2be98ea811
children 2c60e03d2bf6
files src/lib-index/mail-transaction-log.c
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log.c	Wed Jan 17 20:47:46 2007 +0200
+++ b/src/lib-index/mail-transaction-log.c	Wed Jan 17 20:53:27 2007 +0200
@@ -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