From: Carl Worth Date: Wed, 6 Jan 2010 22:35:56 +0000 (-0800) Subject: notmuch new: Never ask the database for any names from a new directory. X-Git-Tag: 0.1~158 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=1a38cb841ca4ce87f6b57f9b1baf1a5f8b8e35b7 notmuch new: Never ask the database for any names from a new directory. 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. --- diff --git a/notmuch-new.c b/notmuch-new.c index 7d15fe91..d1298aff 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -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",