[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-copy.c,1.20,1.21 maildir-save.c,1.19,1.20 maildir-storage.h,1.13,1.14
cras at procontrol.fi
cras at procontrol.fi
Wed Feb 19 23:32:23 EET 2003
Update of /home/cvs/dovecot/src/lib-storage/index/maildir
In directory danu:/tmp/cvs-serv17702/maildir
Modified Files:
maildir-copy.c maildir-save.c maildir-storage.h
Log Message:
Include microseconds in maildir filename base.
Index: maildir-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-copy.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- maildir-copy.c 22 Jan 2003 19:23:28 -0000 1.20
+++ maildir-copy.c 19 Feb 2003 21:32:21 -0000 1.21
@@ -1,6 +1,7 @@
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
+#include "ioloop.h"
#include "maildir-index.h"
#include "maildir-storage.h"
#include "mail-custom-flags.h"
@@ -57,8 +58,9 @@
t_push();
src_path = t_strconcat(index->mailbox_path, "/cur/",
fname, NULL);
- dest_fname = t_strconcat(maildir_filename_set_flags(
- maildir_generate_tmp_filename(), flags), NULL);
+
+ dest_fname = maildir_generate_tmp_filename(&ioloop_timeval);
+ dest_fname = maildir_filename_set_flags(dest_fname, flags);
dest_path = t_strconcat(dest->index->mailbox_path, "/new/",
dest_fname, NULL);
Index: maildir-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-save.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- maildir-save.c 17 Feb 2003 20:45:02 -0000 1.19
+++ maildir-save.c 19 Feb 2003 21:32:21 -0000 1.20
@@ -11,6 +11,9 @@
#include <unistd.h>
#include <fcntl.h>
#include <utime.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <time.h>
struct mail_filename {
struct mail_filename *next;
@@ -27,38 +30,58 @@
struct mail_filename *files;
};
-const char *maildir_generate_tmp_filename(void)
+const char *maildir_generate_tmp_filename(const struct timeval *tv)
{
static unsigned int create_count = 0;
hostpid_init();
-
- return t_strdup_printf("%s.P%sQ%u.%s", dec2str(ioloop_time),
- my_pid, create_count++, my_hostname);
+ 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 int maildir_create_tmp(struct mail_storage *storage, const char *dir,
const char **fname)
{
- const char *path;
+ const char *path, *tmp_fname;
+ struct stat st;
+ struct timeval *tv, tv_now;
+ pool_t pool;
int fd;
- *fname = maildir_generate_tmp_filename();
+ tv = &ioloop_timeval;
+ pool = pool_alloconly_create("maildir_tmp", 4096);
+ for (;;) {
+ p_clear(pool);
+ tmp_fname = maildir_generate_tmp_filename(tv);
- path = t_strconcat(dir, "/", *fname, NULL);
- fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0660);
+ path = p_strconcat(pool, dir, "/", tmp_fname, NULL);
+ if (stat(path, &st) < 0 && errno == ENOENT) {
+ /* doesn't exist */
+ fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
+ if (fd != -1 || errno != EEXIST)
+ break;
+ }
+
+ /* wait and try again - very unlikely */
+ sleep(2);
+ tv = &tv_now;
+ if (gettimeofday(&tv_now, NULL) < 0)
+ i_fatal("gettimeofday(): %m");
+ }
+
+ *fname = t_strdup(tmp_fname);
if (fd == -1) {
if (errno == ENOSPC) {
mail_storage_set_error(storage,
- "Not enough disk space");
+ "Not enough disk space");
} else {
- /* don't bother checking if it was because file
- existed - if that happens it's itself an error. */
- mail_storage_set_critical(storage, "Can't create file "
- "%s: %m", path);
+ mail_storage_set_critical(storage,
+ "Can't create file %s: %m", path);
}
}
+ pool_unref(pool);
return fd;
}
@@ -166,7 +189,8 @@
/* now, if we want to be able to rollback the whole append session,
we'll just store the name of this temp file and move it later
into new/ */
- dest_fname = maildir_filename_set_flags(fname, mail_flags);
+ dest_fname = mail_flags == 0 ? fname :
+ maildir_filename_set_flags(fname, mail_flags);
if (ctx->transaction) {
struct mail_filename *mf;
Index: maildir-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- maildir-storage.h 19 Feb 2003 19:55:27 -0000 1.13
+++ maildir-storage.h 19 Feb 2003 21:32:21 -0000 1.14
@@ -25,7 +25,7 @@
int maildir_expunge_locked(struct index_mailbox *ibox, int notify);
/* Return new filename base to save into tmp/ */
-const char *maildir_generate_tmp_filename(void);
+const char *maildir_generate_tmp_filename(const struct timeval *tv);
const char *maildir_get_path(struct mail_storage *storage, const char *name);
More information about the dovecot-cvs
mailing list