X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;h=44b50aaa2c49ceea06825abea39256790f2c1a5d;hp=3e6b96a7c45688501b512650d9332ac1c02032b2;hb=14e98e454e86d2322ecb6b9dc2364280cde4afbd;hpb=c5416b6f1b2ec0ab1bcc011b521542a7839479d2 diff --git a/notmuch-new.c b/notmuch-new.c index 3e6b96a7..44b50aaa 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -273,9 +273,19 @@ add_files_recursive (notmuch_database_t *notmuch, entry = fs_entries[i]; - if (entry->d_type != DT_DIR && entry->d_type != DT_LNK - && entry->d_type != DT_UNKNOWN) + /* We only want to descend into directories. + * But symlinks can be to directories too, of course. + * + * And if the filesystem doesn't tell us the file type in the + * scandir results, then it might be a directory (and if not, + * then we'll stat and return immediately in the next level of + * recursion). */ + if (entry->d_type != DT_DIR && + entry->d_type != DT_LNK && + entry->d_type != DT_UNKNOWN) + { continue; + } /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory and any "tmp" directory @@ -314,7 +324,7 @@ add_files_recursive (notmuch_database_t *notmuch, /* Check if we've walked past any names in db_files or * db_subdirs. If so, these have been deleted. */ - while (notmuch_filenames_has_more (db_files) && + while (notmuch_filenames_valid (db_files) && strcmp (notmuch_filenames_get (db_files), entry->d_name) < 0) { char *absolute = talloc_asprintf (state->removed_files, @@ -323,10 +333,10 @@ add_files_recursive (notmuch_database_t *notmuch, _filename_list_add (state->removed_files, absolute); - notmuch_filenames_advance (db_files); + notmuch_filenames_move_to_next (db_files); } - while (notmuch_filenames_has_more (db_subdirs) && + while (notmuch_filenames_valid (db_subdirs) && strcmp (notmuch_filenames_get (db_subdirs), entry->d_name) <= 0) { const char *filename = notmuch_filenames_get (db_subdirs); @@ -339,11 +349,17 @@ add_files_recursive (notmuch_database_t *notmuch, _filename_list_add (state->removed_directories, absolute); } - notmuch_filenames_advance (db_subdirs); + notmuch_filenames_move_to_next (db_subdirs); } /* If we're looking at a symlink, we only want to add it if it - * links to a regular file, (and not to a directory, say). */ + * links to a regular file, (and not to a directory, say). + * + * Similarly, if the file is of unknown type (due to filesytem + * limitations), then we also need to look closer. + * + * In either case, a stat does the trick. + */ if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) { int err; @@ -365,10 +381,10 @@ add_files_recursive (notmuch_database_t *notmuch, } /* Don't add a file that we've added before. */ - if (notmuch_filenames_has_more (db_files) && + if (notmuch_filenames_valid (db_files) && strcmp (notmuch_filenames_get (db_files), entry->d_name) == 0) { - notmuch_filenames_advance (db_files); + notmuch_filenames_move_to_next (db_files); continue; } @@ -440,7 +456,7 @@ add_files_recursive (notmuch_database_t *notmuch, /* 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)) + while (notmuch_filenames_valid (db_files)) { char *absolute = talloc_asprintf (state->removed_files, "%s/%s", path, @@ -448,10 +464,10 @@ add_files_recursive (notmuch_database_t *notmuch, _filename_list_add (state->removed_files, absolute); - notmuch_filenames_advance (db_files); + notmuch_filenames_move_to_next (db_files); } - while (notmuch_filenames_has_more (db_subdirs)) + while (notmuch_filenames_valid (db_subdirs)) { char *absolute = talloc_asprintf (state->removed_directories, "%s/%s", path, @@ -459,7 +475,7 @@ add_files_recursive (notmuch_database_t *notmuch, _filename_list_add (state->removed_directories, absolute); - notmuch_filenames_advance (db_subdirs); + notmuch_filenames_move_to_next (db_subdirs); } if (! interrupted) { @@ -660,8 +676,8 @@ _remove_directory (void *ctx, directory = notmuch_database_get_directory (notmuch, path); for (files = notmuch_directory_get_child_files (directory); - notmuch_filenames_has_more (files); - notmuch_filenames_advance (files)) + notmuch_filenames_valid (files); + notmuch_filenames_move_to_next (files)) { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (files)); @@ -674,8 +690,8 @@ _remove_directory (void *ctx, } for (subdirs = notmuch_directory_get_child_directories (directory); - notmuch_filenames_has_more (subdirs); - notmuch_filenames_advance (subdirs)) + notmuch_filenames_valid (subdirs); + notmuch_filenames_move_to_next (subdirs)) { absolute = talloc_asprintf (ctx, "%s/%s", path, notmuch_filenames_get (subdirs));