dovecot: Moved maildir_create_tmp() to maildir-save. It's the on...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 9 05:44:36 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/81b3a22e6ce1
changeset: 5905:81b3a22e6ce1
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jul 08 21:33:42 2007 +0300
description:
Moved maildir_create_tmp() to maildir-save. It's the only place where it's
used.

diffstat:

3 files changed, 52 insertions(+), 54 deletions(-)
src/lib-storage/index/maildir/maildir-save.c    |   52 +++++++++++++++++++++++
src/lib-storage/index/maildir/maildir-storage.h |    2 
src/lib-storage/index/maildir/maildir-util.c    |   52 -----------------------

diffs (136 lines):

diff -r 62ceb6b2b20d -r 81b3a22e6ce1 src/lib-storage/index/maildir/maildir-save.c
--- a/src/lib-storage/index/maildir/maildir-save.c	Sun Jul 08 21:28:54 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Sun Jul 08 21:33:42 2007 +0300
@@ -333,6 +333,58 @@ const char *maildir_save_file_get_path(s
 	return maildir_mf_get_path(ctx, mf);
 }
 
+static int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir,
+			      mode_t mode, const char **fname_r)
+{
+	struct stat st;
+	unsigned int prefix_len;
+	const char *tmp_fname = NULL;
+	string_t *path;
+	int fd;
+
+	path = t_str_new(256);
+	str_append(path, dir);
+	str_append_c(path, '/');
+	prefix_len = str_len(path);
+
+	for (;;) {
+		tmp_fname = maildir_filename_generate();
+		str_truncate(path, prefix_len);
+		str_append(path, tmp_fname);
+
+		/* 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(str_c(path), O_WRONLY | O_CREAT | O_EXCL,
+				  mode);
+			umask(old_mask);
+			if (fd != -1 || errno != EEXIST)
+				break;
+		}
+	}
+
+	*fname_r = tmp_fname;
+	if (fd == -1) {
+		if (ENOSPACE(errno)) {
+			mail_storage_set_error(&mbox->storage->storage,
+				MAIL_ERROR_NOSPACE, MAIL_ERRSTR_NO_SPACE);
+		} else {
+			mail_storage_set_critical(&mbox->storage->storage,
+				"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", str_c(path));
+		}
+	}
+
+	return fd;
+}
+
 int maildir_save_init(struct mailbox_transaction_context *_t,
 		      enum mail_flags flags, struct mail_keywords *keywords,
 		      time_t received_date, int timezone_offset __attr_unused__,
diff -r 62ceb6b2b20d -r 81b3a22e6ce1 src/lib-storage/index/maildir/maildir-storage.h
--- a/src/lib-storage/index/maildir/maildir-storage.h	Sun Jul 08 21:28:54 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Sun Jul 08 21:33:42 2007 +0300
@@ -113,8 +113,6 @@ int maildir_file_do(struct maildir_mailb
 	maildir_file_do(mbox, seq, (maildir_file_do_func *)callback, context)
 #endif
 
-int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir,
-		       mode_t mode, const char **fname_r);
 void maildir_tmp_cleanup(struct mail_storage *storage, const char *dir);
 
 void maildir_transaction_class_init(void);
diff -r 62ceb6b2b20d -r 81b3a22e6ce1 src/lib-storage/index/maildir/maildir-util.c
--- a/src/lib-storage/index/maildir/maildir-util.c	Sun Jul 08 21:28:54 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-util.c	Sun Jul 08 21:33:42 2007 +0300
@@ -84,58 +84,6 @@ int maildir_file_do(struct maildir_mailb
 	return ret == -2 ? 0 : ret;
 }
 
-int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir,
-		       mode_t mode, const char **fname_r)
-{
-	struct stat st;
-	unsigned int prefix_len;
-	const char *tmp_fname = NULL;
-	string_t *path;
-	int fd;
-
-	path = t_str_new(256);
-	str_append(path, dir);
-	str_append_c(path, '/');
-	prefix_len = str_len(path);
-
-	for (;;) {
-		tmp_fname = maildir_filename_generate();
-		str_truncate(path, prefix_len);
-		str_append(path, tmp_fname);
-
-		/* 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(str_c(path), O_WRONLY | O_CREAT | O_EXCL,
-				  mode);
-			umask(old_mask);
-			if (fd != -1 || errno != EEXIST)
-				break;
-		}
-	}
-
-	*fname_r = tmp_fname;
-	if (fd == -1) {
-		if (ENOSPACE(errno)) {
-			mail_storage_set_error(&mbox->storage->storage,
-				MAIL_ERROR_NOSPACE, MAIL_ERRSTR_NO_SPACE);
-		} else {
-			mail_storage_set_critical(&mbox->storage->storage,
-				"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", str_c(path));
-		}
-	}
-
-	return fd;
-}
-
 void maildir_tmp_cleanup(struct mail_storage *storage, const char *dir)
 {
 	DIR *dirp;


More information about the dovecot-cvs mailing list