[dovecot-cvs] dovecot/src/lib-index/maildir maildir-index.c,1.35,1.36

cras at procontrol.fi cras at procontrol.fi
Sun Aug 24 04:50:24 EEST 2003


Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv22622/lib-index/maildir

Modified Files:
	maildir-index.c 
Log Message:
Don't use microseconds in maildir name if it's not needed.



Index: maildir-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- maildir-index.c	10 Aug 2003 23:56:23 -0000	1.35
+++ maildir-index.c	24 Aug 2003 00:50:22 -0000	1.36
@@ -112,10 +112,23 @@
 const char *maildir_generate_tmp_filename(const struct timeval *tv)
 {
 	static unsigned int create_count = 0;
+	static time_t first_stamp = 0;
 
-	return t_strdup_printf("%s.P%sQ%uM%s.%s",
-			       dec2str(tv->tv_sec), my_pid, create_count++,
-			       dec2str(tv->tv_usec), my_hostname);
+	if (first_stamp == 0 || first_stamp == ioloop_time) {
+		/* it's possible that within last second another process had
+		   the same UID as us. Use usecs to make sure we don't create
+		   duplicate base name. */
+		first_stamp = ioloop_time;
+		return t_strdup_printf("%s.P%sQ%uM%s.%s",
+				       dec2str(tv->tv_sec), my_pid,
+				       create_count++,
+				       dec2str(tv->tv_usec), my_hostname);
+	} else {
+		/* Don't bother with usecs. Saves a bit space :) */
+		return t_strdup_printf("%s.P%sQ%u.%s",
+				       dec2str(tv->tv_sec), my_pid,
+				       create_count++, my_hostname);
+	}
 }
 
 int maildir_create_tmp(struct mail_index *index, const char *dir,



More information about the dovecot-cvs mailing list