[PATCH 05/18] insert: move file from Maildir tmp to new
Mark Walters
markwalters1009 at gmail.com
Sun Nov 18 09:33:46 PST 2012
On Wed, 25 Jul 2012, Peter Wang <novalazy at gmail.com> wrote:
> 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;
> + }
Do we want to overwrite an existing message with this name? As far as I
can see rename does overwrite and link would not: was that why rename is
better than link/unlink?
I would prefer not to overwrite but maybe there is a reason we need to.
Would a possible alternative be to loop when finding a tmp file until
both the tmp file and the new file do not exist?
Best wishes
Mark
> +
> + 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
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
More information about the notmuch
mailing list