]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch new: Never ask the database for any names from a new directory.
authorCarl Worth <cworth@cworth.org>
Wed, 6 Jan 2010 22:35:56 +0000 (14:35 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 6 Jan 2010 22:35:56 +0000 (14:35 -0800)
When we know that we are adding a new directory to the database, (and
we therefore are using inode rather than strcmp-based sorting of the
filenames), then we *never* want to see any names from the
database. If we get any names that could only make us inadvertently
remove files that we just added.

Since it's not obvious from the Xapian documentation whether new terms
being added as part of new documents will appear in the in-progress
all-terms iteration we are using, (and this might differ based on
Xapian backend and also might differ based on how many new directories
are added and whether a flush threshold is reached).

For all of these reasons, we play it safe and use NULL rather than a
real notmuch_filenames_t iterator in this case to avoid any problem.

notmuch-new.c

index 7d15fe9184183401ab96556ff9f6d7c6168be8c9..d1298aff84168fb2295a0132eb2ab7b6e8ad90be 100644 (file)
@@ -221,7 +221,7 @@ add_files_recursive (notmuch_database_t *notmuch,
     notmuch_filenames_t *db_files = NULL;
     notmuch_filenames_t *db_subdirs = NULL;
     struct stat st;
-    notmuch_bool_t is_maildir;
+    notmuch_bool_t is_maildir, new_directory;
 
     if (stat (path, &st)) {
        fprintf (stderr, "Error reading directory %s: %s\n",
@@ -239,15 +239,23 @@ 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 (db_mtime == 0) {
+       new_directory = TRUE;
+       db_files = NULL;
+       db_subdirs = NULL;
+    } else {
+       new_directory = FALSE;
+       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
      * inode-based sorting for faster filesystem operation. */
     num_fs_entries = scandir (path, &fs_entries, 0,
-                             db_mtime ?
-                             dirent_sort_strcmp_name : dirent_sort_inode);
+                             new_directory ?
+                             dirent_sort_inode : dirent_sort_strcmp_name);
 
     if (num_fs_entries == -1) {
        fprintf (stderr, "Error opening directory %s: %s\n",