From: Timo Sirainen Date: Sun, 24 Aug 2003 00:50:22 +0000 (+0300) Subject: Don't use microseconds in maildir name if it's not needed. X-Git-Tag: 1.1.alpha1~4391 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41864983cecb9c3ee333450f6143b7a3ef4d9886;p=thirdparty%2Fdovecot%2Fcore.git Don't use microseconds in maildir name if it's not needed. --HG-- branch : HEAD --- diff --git a/src/lib-index/maildir/maildir-index.c b/src/lib-index/maildir/maildir-index.c index e8b9983522..5b9c1de4a7 100644 --- a/src/lib-index/maildir/maildir-index.c +++ b/src/lib-index/maildir/maildir-index.c @@ -112,10 +112,23 @@ int maildir_file_do(struct mail_index *index, struct mail_index_record *rec, const char *maildir_generate_tmp_filename(const struct timeval *tv) { static unsigned int create_count = 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); + static time_t first_stamp = 0; + + 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,