[PATCH 05/18] insert: move file from Maildir tmp to new
Peter Wang
novalazy at gmail.com
Wed Jul 25 06:42:34 PDT 2012
Atomically move the new message file from the Maildir 'tmp' directory
to 'new'.
---
notmuch-insert.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 340f7e4..bab1fed 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -75,6 +75,20 @@ maildir_open_tmp (void *ctx, const char *dir, char **tmppath, char **newpath)
}
static notmuch_bool_t
+maildir_move_to_new (const char *tmppath, const char *newpath)
+{
+ /* We follow the Dovecot recommendation to simply use rename()
+ * instead of link() and unlink().
+ */
+ if (rename (tmppath, newpath) == 0) {
+ return TRUE;
+ }
+
+ fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno));
+ return FALSE;
+}
+
+static notmuch_bool_t
copy_fd_data (int fdin, int fdout)
{
char buf[4096];
@@ -132,6 +146,10 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
close (fdout);
+ if (ret) {
+ ret = maildir_move_to_new (tmppath, newpath);
+ }
+
if (!ret) {
unlink (tmppath);
}
--
1.7.4.4
More information about the notmuch
mailing list