[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-save.c, 1.84, 1.85 maildir-util.c, 1.23, 1.24

tss at dovecot.org tss at dovecot.org
Mon Apr 2 05:49:16 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/index/maildir
In directory talvi:/tmp/cvs-serv30342

Modified Files:
	maildir-save.c maildir-util.c 
Log Message:
Cleaned up maildir_create_tmp() a bit. It now also returns the filename
instead of the whole path, as was originally intended.



Index: maildir-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-save.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- maildir-save.c	30 Mar 2007 12:44:03 -0000	1.84
+++ maildir-save.c	2 Apr 2007 02:49:14 -0000	1.85
@@ -334,7 +334,7 @@
 	struct maildir_save_context *ctx;
 	struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox;
 	struct ostream *output;
-	const char *fname, *path;
+	const char *fname;
 
 	i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
 
@@ -346,17 +346,13 @@
 
 	/* create a new file in tmp/ directory */
 	ctx->fd = maildir_create_tmp(mbox, ctx->tmpdir, mbox->mail_create_mode,
-				     &path);
+				     &fname);
 	if (ctx->fd == -1) {
 		ctx->failed = TRUE;
 		t_pop();
 		return -1;
 	}
 
-	fname = strrchr(path, '/');
-	i_assert(fname != NULL);
-	fname++;
-
 	ctx->received_date = received_date;
 	ctx->input = input;
 

Index: maildir-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-util.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- maildir-util.c	30 Mar 2007 12:44:03 -0000	1.23
+++ maildir-util.c	2 Apr 2007 02:49:14 -0000	1.24
@@ -94,52 +94,59 @@
 int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir,
 		       mode_t mode, const char **fname_r)
 {
-	const char *path, *tmp_fname;
 	struct stat st;
 	struct timeval *tv, tv_now;
-	pool_t pool;
+	unsigned int prefix_len;
+	const char *tmp_fname = NULL;
+	string_t *path;
 	int fd;
 
 	tv = &ioloop_timeval;
-	pool = pool_alloconly_create("maildir_tmp", 4096);
+	path = t_str_new(256);
+	str_append(path, dir);
+	str_append_c(path, '/');
+	prefix_len = str_len(path);
+
 	for (;;) {
-		p_clear(pool);
 		tmp_fname = maildir_generate_tmp_filename(tv);
+		str_truncate(path, prefix_len);
+		str_append(path, tmp_fname);
 
-		path = p_strconcat(pool, dir, "/", tmp_fname, NULL);
-		if (stat(path, &st) < 0 && errno == ENOENT) {
+		/* stat() first to see if it exists. pretty much the only
+		   possibility of that happening is if time had moved
+		   backwards, but even then it's highly unlikely. */
+		if (stat(str_c(path), &st) < 0 && errno == ENOENT) {
 			/* doesn't exist */
 			mode_t old_mask = umask(0);
-			fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
+			fd = open(str_c(path), O_WRONLY | O_CREAT | O_EXCL,
+				  mode);
 			umask(old_mask);
 			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_r = t_strdup(path);
+	*fname_r = tmp_fname;
 	if (fd == -1) {
 		if (ENOSPACE(errno)) {
 			mail_storage_set_error(&mbox->storage->storage,
 					       "Not enough disk space");
 		} else {
 			mail_storage_set_critical(&mbox->storage->storage,
-						  "open(%s) failed: %m", path);
+				"open(%s) failed: %m", str_c(path));
 		}
 	} else if (mbox->mail_create_gid != (gid_t)-1) {
 		if (fchown(fd, (uid_t)-1, mbox->mail_create_gid) < 0) {
 			mail_storage_set_critical(&mbox->storage->storage,
-				"fchown(%s) failed: %m", path);
+				"fchown(%s) failed: %m", str_c(path));
 		}
 	}
 
-	pool_unref(pool);
 	return fd;
 }
 



More information about the dovecot-cvs mailing list