]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-new.c
lib: Treat NULL as a valid (and empty) notmuch_filenames_t iterator.
[notmuch] / notmuch-new.c
index 432d126286fba8fd070ad75d18850ecca38caef9..7d15fe9184183401ab96556ff9f6d7c6168be8c9 100644 (file)
@@ -239,6 +239,8 @@ add_files_recursive (notmuch_database_t *notmuch,
 
     directory = notmuch_database_get_directory (notmuch, path);
     db_mtime = notmuch_directory_get_mtime (directory);
+    db_files = notmuch_directory_get_child_files (directory);
+    db_subdirs = notmuch_directory_get_child_directories (directory);
 
     /* If the database knows about this directory, then we sort based
      * on strcmp to match the database sorting. Otherwise, we can do
@@ -294,9 +296,6 @@ add_files_recursive (notmuch_database_t *notmuch,
        goto DONE;
 
     /* Pass 2: Scan for new files, removed files, and removed directories. */
-    db_files = notmuch_directory_get_child_files (directory);
-    db_subdirs = notmuch_directory_get_child_directories (directory);
-
     for (i = 0; i < num_fs_entries; i++)
     {
        if (interrupted)
@@ -430,6 +429,30 @@ add_files_recursive (notmuch_database_t *notmuch,
        next = NULL;
     }
 
+    /* Now that we've walked the whole filesystem list, anything left
+     * over in the database lists has been deleted. */
+    while (notmuch_filenames_has_more (db_files))
+    {
+       char *absolute = talloc_asprintf (state->removed_files,
+                                         "%s/%s", path,
+                                         notmuch_filenames_get (db_files));
+
+       _filename_list_add (state->removed_files, absolute);
+
+       notmuch_filenames_advance (db_files);
+    }
+
+    while (notmuch_filenames_has_more (db_subdirs))
+    {
+       char *absolute = talloc_asprintf (state->removed_directories,
+                                         "%s/%s", path,
+                                         notmuch_filenames_get (db_subdirs));
+
+       _filename_list_add (state->removed_directories, absolute);
+
+       notmuch_filenames_advance (db_subdirs);
+    }
+
     if (! interrupted) {
        status = notmuch_directory_set_mtime (directory, fs_mtime);
        if (status && ret == NOTMUCH_STATUS_SUCCESS)