]> git.notmuchmail.org Git - notmuch/commitdiff
new: Consistently treat fatal errors as fatal
authorAustin Clements <amdragon@MIT.EDU>
Sun, 22 Apr 2012 15:50:49 +0000 (11:50 -0400)
committerDavid Bremner <bremner@debian.org>
Wed, 25 Apr 2012 02:25:51 +0000 (23:25 -0300)
Previously, fatal errors in add_files_recursive were not treated as
fatal by its callers (including itself!).  This makes
add_files_recursive errors consistently fatal and updates all callers
to treat them as fatal.

notmuch-new.c

index 4f13535c75d92f5755502125462e54464c613497..15c0b36db5ee57d98aef916e4b1c3e345de88c17 100644 (file)
@@ -308,6 +308,10 @@ add_files_recursive (notmuch_database_t *notmuch,
     if (num_fs_entries == -1) {
        fprintf (stderr, "Error opening directory %s: %s\n",
                 path, strerror (errno));
     if (num_fs_entries == -1) {
        fprintf (stderr, "Error opening directory %s: %s\n",
                 path, strerror (errno));
+       /* We consider this a fatal error because, if a user moved a
+        * message from another directory that we were able to scan
+        * into this directory, skipping this directory will cause
+        * that message to be lost. */
        ret = NOTMUCH_STATUS_FILE_ERROR;
        goto DONE;
     }
        ret = NOTMUCH_STATUS_FILE_ERROR;
        goto DONE;
     }
@@ -351,8 +355,10 @@ add_files_recursive (notmuch_database_t *notmuch,
 
        next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
        status = add_files_recursive (notmuch, next, state);
 
        next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
        status = add_files_recursive (notmuch, next, state);
-       if (status && ret == NOTMUCH_STATUS_SUCCESS)
+       if (status) {
            ret = status;
            ret = status;
+           goto DONE;
+       }
        talloc_free (next);
        next = NULL;
     }
        talloc_free (next);
        next = NULL;
     }
@@ -933,6 +939,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     }
 
     ret = add_files (notmuch, db_path, &add_files_state);
     }
 
     ret = add_files (notmuch, db_path, &add_files_state);
+    if (ret)
+       goto DONE;
 
     gettimeofday (&tv_start, NULL);
     for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
 
     gettimeofday (&tv_start, NULL);
     for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
@@ -965,6 +973,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
        }
     }
 
        }
     }
 
+  DONE:
     talloc_free (add_files_state.removed_files);
     talloc_free (add_files_state.removed_directories);
     talloc_free (add_files_state.directory_mtimes);
     talloc_free (add_files_state.removed_files);
     talloc_free (add_files_state.removed_directories);
     talloc_free (add_files_state.directory_mtimes);
@@ -1012,10 +1021,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
 
     printf ("\n");
 
 
     printf ("\n");
 
-    if (ret) {
-       printf ("\nNote: At least one error was encountered: %s\n",
+    if (ret)
+       printf ("\nNote: A fatal error was encountered: %s\n",
                notmuch_status_to_string (ret));
                notmuch_status_to_string (ret));
-    }
 
     notmuch_database_close (notmuch);
 
 
     notmuch_database_close (notmuch);