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.
This commit is contained in:
Carl Worth 2010-01-06 14:35:56 -08:00
parent 957ae198e7
commit 1a38cb841c

View file

@ -221,7 +221,7 @@ add_files_recursive (notmuch_database_t *notmuch,
notmuch_filenames_t *db_files = NULL; notmuch_filenames_t *db_files = NULL;
notmuch_filenames_t *db_subdirs = NULL; notmuch_filenames_t *db_subdirs = NULL;
struct stat st; struct stat st;
notmuch_bool_t is_maildir; notmuch_bool_t is_maildir, new_directory;
if (stat (path, &st)) { if (stat (path, &st)) {
fprintf (stderr, "Error reading directory %s: %s\n", 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); directory = notmuch_database_get_directory (notmuch, path);
db_mtime = notmuch_directory_get_mtime (directory); db_mtime = notmuch_directory_get_mtime (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_files = notmuch_directory_get_child_files (directory);
db_subdirs = notmuch_directory_get_child_directories (directory); db_subdirs = notmuch_directory_get_child_directories (directory);
}
/* If the database knows about this directory, then we sort based /* If the database knows about this directory, then we sort based
* on strcmp to match the database sorting. Otherwise, we can do * on strcmp to match the database sorting. Otherwise, we can do
* inode-based sorting for faster filesystem operation. */ * inode-based sorting for faster filesystem operation. */
num_fs_entries = scandir (path, &fs_entries, 0, num_fs_entries = scandir (path, &fs_entries, 0,
db_mtime ? new_directory ?
dirent_sort_strcmp_name : dirent_sort_inode); dirent_sort_inode : dirent_sort_strcmp_name);
if (num_fs_entries == -1) { if (num_fs_entries == -1) {
fprintf (stderr, "Error opening directory %s: %s\n", fprintf (stderr, "Error opening directory %s: %s\n",