]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-new.c
new: Don't lose messages on SIGINT.
[notmuch] / notmuch-new.c
index c1805916671e340412ba40345f8aadd17a4b2318..b734e5b972373d6b4941b8c711cf99f87056b097 100644 (file)
@@ -256,6 +256,25 @@ add_files_recursive (notmuch_database_t *notmuch,
 
     new_directory = db_mtime ? FALSE : TRUE;
 
+    /* XXX This is a temporary workaround.  If we don't update the
+     * database mtime until after processing messages in this
+     * directory, then a 0 mtime is *not* sufficient to indicate that
+     * this directory has no messages or subdirs in the database (for
+     * example, if an earlier run skipped the mtime update because
+     * fs_mtime == stat_time, or was interrupted before updating the
+     * mtime at the end).  To address this, we record a (bogus)
+     * non-zero value before processing any child messages so that a
+     * later run won't mistake this for a new directory (and, for
+     * example, fail to detect removed files and subdirs).
+     *
+     * A better solution would be for notmuch_database_get_directory
+     * to indicate if it really created a new directory or not, either
+     * by a new out-argument, or by recording this information and
+     * providing an accessor.
+     */
+    if (new_directory)
+       notmuch_directory_set_mtime (directory, -1);
+
     /* If the database knows about this directory, then we sort based
      * on strcmp to match the database sorting. Otherwise, we can do
      * inode-based sorting for faster filesystem operation. */
@@ -516,17 +535,7 @@ add_files_recursive (notmuch_database_t *notmuch,
      * when we stat'ed the directory, we skip updating the mtime in
      * the database because a message could be delivered later in this
      * same second.  This may lead to unnecessary re-scans, but it
-     * avoids overlooking messages.
-     *
-     * XXX Bug workaround: If this is a new directory, we *must*
-     * update the mtime; otherwise the next run will see the 0 mtime
-     * and think this is still a new directory containing no files or
-     * subdirs (which is unsound in general).  If fs_mtime ==
-     * stat_time, we set the database mtime to a bogus (but non-zero!)
-     * value to force a rescan.
-     */
-    if (new_directory && fs_mtime == stat_time)
-       fs_mtime = 1;
+     * avoids overlooking messages. */
     if (! interrupted && fs_mtime != stat_time) {
        status = notmuch_directory_set_mtime (directory, fs_mtime);
        if (status && ret == NOTMUCH_STATUS_SUCCESS)
@@ -859,7 +868,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     removed_files = 0;
     renamed_files = 0;
     gettimeofday (&tv_start, NULL);
-    for (f = add_files_state.removed_files->head; f; f = f->next) {
+    for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
        status = notmuch_database_remove_message (notmuch, f->filename);
        if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
            renamed_files++;
@@ -874,7 +883,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     }
 
     gettimeofday (&tv_start, NULL);
-    for (f = add_files_state.removed_directories->head, i = 0; f; f = f->next, i++) {
+    for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
        _remove_directory (ctx, notmuch, f->filename,
                           &renamed_files, &removed_files);
        if (do_print_progress) {