dovecot: Renamed maildir_generate_tmp_filename() to maildir_file...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 9 05:44:36 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/62ceb6b2b20d
changeset: 5904:62ceb6b2b20d
user: Timo Sirainen <tss at iki.fi>
date: Sun Jul 08 21:28:54 2007 +0300
description:
Renamed maildir_generate_tmp_filename() to maildir_filename_generate(). Also
changed it to create the unique filename with time+usecs+pid, increasing
usecs as needed. So there's no longer a process delivery counter.
diffstat:
5 files changed, 26 insertions(+), 32 deletions(-)
src/lib-storage/index/maildir/maildir-copy.c | 3 -
src/lib-storage/index/maildir/maildir-filename.c | 42 +++++++++++-----------
src/lib-storage/index/maildir/maildir-filename.h | 2 -
src/lib-storage/index/maildir/maildir-sync.c | 2 -
src/lib-storage/index/maildir/maildir-util.c | 9 ----
diffs (126 lines):
diff -r 5d0827cd9839 -r 62ceb6b2b20d src/lib-storage/index/maildir/maildir-copy.c
--- a/src/lib-storage/index/maildir/maildir-copy.c Sun Jul 08 21:24:57 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-copy.c Sun Jul 08 21:28:54 2007 +0300
@@ -140,8 +140,7 @@ maildir_copy_hardlink(struct maildir_tra
if (filename == NULL) {
/* the generated filename is _always_ unique, so we don't
bother trying to check if it already exists */
- do_ctx.dest_fname =
- maildir_generate_tmp_filename(&ioloop_timeval);
+ do_ctx.dest_fname = maildir_filename_generate();
} else {
do_ctx.dest_fname = filename;
do_ctx.preserve_filename = TRUE;
diff -r 5d0827cd9839 -r 62ceb6b2b20d src/lib-storage/index/maildir/maildir-filename.c
--- a/src/lib-storage/index/maildir/maildir-filename.c Sun Jul 08 21:24:57 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-filename.c Sun Jul 08 21:28:54 2007 +0300
@@ -11,26 +11,28 @@
#include <stdlib.h>
-const char *maildir_generate_tmp_filename(const struct timeval *tv)
-{
- static unsigned int create_count = 0;
- 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 PID 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);
- }
+const char *maildir_filename_generate(void)
+{
+ static struct timeval last_tv = { 0, 0 };
+ struct timeval tv;
+
+ /* use secs + usecs to guarantee uniqueness within this process. */
+ if (ioloop_timeval.tv_sec > last_tv.tv_sec ||
+ (ioloop_timeval.tv_sec == last_tv.tv_sec &&
+ ioloop_timeval.tv_usec > last_tv.tv_usec))
+ tv = ioloop_timeval;
+ else {
+ tv = last_tv;
+ if (++tv.tv_usec == 1000000) {
+ tv.tv_sec++;
+ tv.tv_usec = 0;
+ }
+ }
+ last_tv = tv;
+
+ return t_strdup_printf("%s.M%sP%s.%s",
+ dec2str(tv.tv_sec), dec2str(tv.tv_usec),
+ my_pid, my_hostname);
}
void maildir_filename_get_flags(struct maildir_keywords_sync_ctx *ctx,
diff -r 5d0827cd9839 -r 62ceb6b2b20d src/lib-storage/index/maildir/maildir-filename.h
--- a/src/lib-storage/index/maildir/maildir-filename.h Sun Jul 08 21:24:57 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-filename.h Sun Jul 08 21:28:54 2007 +0300
@@ -3,7 +3,7 @@
struct maildir_keywords_sync_ctx;
-const char *maildir_generate_tmp_filename(const struct timeval *tv);
+const char *maildir_filename_generate(void);
void maildir_filename_get_flags(struct maildir_keywords_sync_ctx *ctx,
const char *fname, enum mail_flags *flags_r,
diff -r 5d0827cd9839 -r 62ceb6b2b20d src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c Sun Jul 08 21:24:57 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c Sun Jul 08 21:28:54 2007 +0300
@@ -605,7 +605,7 @@ static int maildir_fix_duplicate(struct
return 0;
}
- new_fname = maildir_generate_tmp_filename(&ioloop_timeval);
+ new_fname = maildir_filename_generate();
new_path = t_strconcat(mbox->path, "/new/", new_fname, NULL);
if (rename(old_path, new_path) == 0)
diff -r 5d0827cd9839 -r 62ceb6b2b20d src/lib-storage/index/maildir/maildir-util.c
--- a/src/lib-storage/index/maildir/maildir-util.c Sun Jul 08 21:24:57 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-util.c Sun Jul 08 21:28:54 2007 +0300
@@ -88,20 +88,18 @@ int maildir_create_tmp(struct maildir_ma
mode_t mode, const char **fname_r)
{
struct stat st;
- struct timeval *tv, tv_now;
unsigned int prefix_len;
const char *tmp_fname = NULL;
string_t *path;
int fd;
- tv = &ioloop_timeval;
path = t_str_new(256);
str_append(path, dir);
str_append_c(path, '/');
prefix_len = str_len(path);
for (;;) {
- tmp_fname = maildir_generate_tmp_filename(tv);
+ tmp_fname = maildir_filename_generate();
str_truncate(path, prefix_len);
str_append(path, tmp_fname);
@@ -117,11 +115,6 @@ int maildir_create_tmp(struct maildir_ma
if (fd != -1 || errno != EEXIST)
break;
}
-
- sleep(2);
- tv = &tv_now;
- if (gettimeofday(&tv_now, NULL) < 0)
- i_fatal("gettimeofday(): %m");
}
*fname_r = tmp_fname;
More information about the dovecot-cvs
mailing list