From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id C996C431FBF for ; Sun, 21 Jul 2013 01:31:39 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id akDLPjnenOgg for ; Sun, 21 Jul 2013 01:31:32 -0700 (PDT) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B84E4431FB6 for ; Sun, 21 Jul 2013 01:31:31 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1V0p3B-0004q6-Uw; Sun, 21 Jul 2013 09:31:30 +0100 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) (envelope-from ) id 1V0p3B-0001p5-Gz; Sun, 21 Jul 2013 09:31:29 +0100 From: Mark Walters To: Peter Wang , notmuch@notmuchmail.org Subject: Re: [PATCH 1/3] cli: add insert --must-index option In-Reply-To: <1374365254-13227-1-git-send-email-novalazy@gmail.com> References: <1374365254-13227-1-git-send-email-novalazy@gmail.com> User-Agent: Notmuch/0.15.2+192~g8222af3 (http://notmuchmail.org) Emacs/23.4.1 (i486-pc-linux-gnu) Date: Sun, 21 Jul 2013 09:31:28 +0100 Message-ID: <87ip048gbj.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 93.97.24.31 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 751478499e78726c76f7a8c9290d1a63 (of first 20000 bytes) X-SpamAssassin-Score: 0.0 X-SpamAssassin-SpamBar: / X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored 0.0 points. Summary of the scoring: * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * 0.0 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Jul 2013 08:31:40 -0000 Do you have a particular use case where indexing is required but tagging is not? For my uses I would prefer failing if either indexing or tagging failed. (My use being postponing messages; If they don't get the postponed tag they could be hard to find) Best wishes Mark Peter Wang writes: > This option causes notmuch insert to fail as a whole if the message > failed to be added to the notmuch database. The new message file > will be deleted from disk, and a distinct status code (2) returned. > --- > notmuch-insert.c | 76 ++++++++++++++++++++++++++++++++++---------------------- > 1 file changed, 46 insertions(+), 30 deletions(-) > > diff --git a/notmuch-insert.c b/notmuch-insert.c > index 2207b1e..505b647 100644 > --- a/notmuch-insert.c > +++ b/notmuch-insert.c > @@ -28,6 +28,10 @@ > #include > #include > > +#define INSERT_EXIT_SUCCESS 0 > +#define INSERT_EXIT_FAIL_WRITE 1 > +#define INSERT_EXIT_FAIL_INDEX 2 > + > static volatile sig_atomic_t interrupted; > > static void > @@ -293,12 +297,13 @@ copy_stdin (int fdin, int fdout) > > /* Add the specified message file to the notmuch database, applying tags. > * The file is renamed to encode notmuch tags as maildir flags. */ > -static void > +static notmuch_status_t > add_file_to_database (notmuch_database_t *notmuch, const char *path, > tag_op_list_t *tag_ops) > { > notmuch_message_t *message; > notmuch_status_t status; > + notmuch_status_t sync; > > status = notmuch_database_add_message (notmuch, path, &message); > switch (status) { > @@ -318,47 +323,52 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path, > case NOTMUCH_STATUS_LAST_STATUS: > fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n", > path, notmuch_status_to_string (status)); > - return; > + return status; > } > > if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { > /* Don't change tags of an existing message. */ > - status = notmuch_message_tags_to_maildir_flags (message); > - if (status != NOTMUCH_STATUS_SUCCESS) > + sync = notmuch_message_tags_to_maildir_flags (message); > + if (sync != NOTMUCH_STATUS_SUCCESS) > fprintf (stderr, "Error: failed to sync tags to maildir flags\n"); > } else { > tag_op_list_apply (message, tag_ops, TAG_FLAG_MAILDIR_SYNC); > } > > notmuch_message_destroy (message); > + > + return status; > } > > -static notmuch_bool_t > +static int > insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, > - const char *dir, tag_op_list_t *tag_ops) > + const char *dir, tag_op_list_t *tag_ops, > + notmuch_bool_t must_index) > { > char *tmppath; > char *newpath; > char *newdir; > int fdout; > - char *cleanup_path; > + notmuch_status_t status; > > fdout = maildir_open_tmp_file (ctx, dir, &tmppath, &newpath, &newdir); > if (fdout < 0) > - return FALSE; > + return INSERT_EXIT_FAIL_WRITE; > > - cleanup_path = tmppath; > - > - if (! copy_stdin (fdin, fdout)) > - goto FAIL; > + if (! copy_stdin (fdin, fdout)) { > + close (fdout); > + unlink (tmppath); > + return INSERT_EXIT_FAIL_WRITE; > + } > > if (fsync (fdout) != 0) { > fprintf (stderr, "Error: fsync failed: %s\n", strerror (errno)); > - goto FAIL; > + close (fdout); > + unlink (tmppath); > + return INSERT_EXIT_FAIL_WRITE; > } > > close (fdout); > - fdout = -1; > > /* Atomically move the new message file from the Maildir 'tmp' directory > * to the 'new' directory. We follow the Dovecot recommendation to > @@ -367,25 +377,28 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, > */ > if (rename (tmppath, newpath) != 0) { > fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno)); > - goto FAIL; > + unlink (tmppath); > + return INSERT_EXIT_FAIL_WRITE; > } > > - cleanup_path = newpath; > - > - if (! sync_dir (newdir)) > - goto FAIL; > + if (! sync_dir (newdir)) { > + unlink (newpath); > + return INSERT_EXIT_FAIL_WRITE; > + } > > - /* Even if adding the message to the notmuch database fails, > - * the message is on disk and we consider the delivery completed. */ > - add_file_to_database (notmuch, newpath, tag_ops); > + status = add_file_to_database (notmuch, newpath, tag_ops); > > - return TRUE; > + /* If must_index is TRUE, then indexing must succeed. Otherwise, we > + * consider the delivery completed as long as the message is on disk. */ > + if (must_index && > + status != NOTMUCH_STATUS_SUCCESS && > + status != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) > + { > + unlink (newpath); > + return INSERT_EXIT_FAIL_INDEX; > + } > > - FAIL: > - if (fdout >= 0) > - close (fdout); > - unlink (cleanup_path); > - return FALSE; > + return INSERT_EXIT_SUCCESS; > } > > int > @@ -400,6 +413,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) > char *query_string = NULL; > const char *folder = NULL; > notmuch_bool_t create_folder = FALSE; > + notmuch_bool_t must_index = FALSE; > const char *maildir; > int opt_index; > unsigned int i; > @@ -408,6 +422,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) > notmuch_opt_desc_t options[] = { > { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 }, > { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 }, > + { NOTMUCH_OPT_BOOLEAN, &must_index, "must-index", 0, 0 }, > { NOTMUCH_OPT_END, 0, 0, 0, 0 } > }; > > @@ -471,9 +486,10 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) > NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) > return 1; > > - ret = insert_message (config, notmuch, STDIN_FILENO, maildir, tag_ops); > + ret = insert_message (config, notmuch, STDIN_FILENO, maildir, tag_ops, > + must_index); > > notmuch_database_destroy (notmuch); > > - return (ret) ? 0 : 1; > + return ret; > } > -- > 1.7.12.1 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch