]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-new.c
cli: reset db directory mtime upon directory removal
[notmuch] / notmuch-new.c
index 5ac7eedff70bfff763bbe29e39a3f369f7537650..33645349cd5fd8abdb5936e185b5f5c70d529c08 100644 (file)
@@ -528,6 +528,10 @@ add_files (notmuch_database_t *notmuch,
                                              "%s/%s", path,
                                              notmuch_filenames_get (db_files));
 
+           if (state->debug)
+               printf ("(D) add_files_recursive, pass 2: queuing passed file %s for deletion from database\n",
+                       absolute);
+
            _filename_list_add (state->removed_files, absolute);
 
            notmuch_filenames_move_to_next (db_files);
@@ -542,6 +546,9 @@ add_files (notmuch_database_t *notmuch,
            {
                char *absolute = talloc_asprintf (state->removed_directories,
                                                  "%s/%s", path, filename);
+               if (state->debug)
+                   printf ("(D) add_files_recursive, pass 2: queuing passed directory %s for deletion from database\n",
+                       absolute);
 
                _filename_list_add (state->removed_directories, absolute);
            }
@@ -610,6 +617,9 @@ add_files (notmuch_database_t *notmuch,
        char *absolute = talloc_asprintf (state->removed_files,
                                          "%s/%s", path,
                                          notmuch_filenames_get (db_files));
+       if (state->debug)
+           printf ("(D) add_files_recursive, pass 3: queuing leftover file %s for deletion from database\n",
+                   absolute);
 
        _filename_list_add (state->removed_files, absolute);
 
@@ -622,6 +632,10 @@ add_files (notmuch_database_t *notmuch,
                                          "%s/%s", path,
                                          notmuch_filenames_get (db_subdirs));
 
+       if (state->debug)
+           printf ("(D) add_files_recursive, pass 3: queuing leftover directory %s for deletion from database\n",
+                   absolute);
+
        _filename_list_add (state->removed_directories, absolute);
 
        notmuch_filenames_move_to_next (db_subdirs);
@@ -864,6 +878,15 @@ _remove_directory (void *ctx,
            goto DONE;
     }
 
+    /*
+     * XXX: The library does not have a function to remove a directory
+     * document for a path. Usually this doesn't matter except for a
+     * slight waste of space. However, if the directory gets added to
+     * the filesystem again, the old directory document is found with
+     * the old mtime. Reset the directory mtime to avoid problems.
+     */
+    notmuch_directory_set_mtime (directory, 0);
+
   DONE:
     notmuch_directory_destroy (directory);
     return status;
@@ -934,6 +957,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
        { NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },
        { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },
        { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },
+       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -941,6 +965,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     if (opt_index < 0)
        return EXIT_FAILURE;
 
+    notmuch_process_shared_options (argv[0]);
+
     /* quiet trumps verbose */
     if (quiet)
        add_files_state.verbosity = VERBOSITY_QUIET;
@@ -992,10 +1018,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
                fputs (status_string, stderr);
                free (status_string);
            }
-
            return EXIT_FAILURE;
        }
 
+       notmuch_exit_if_unmatched_db_uuid (notmuch);
+
        if (notmuch_database_needs_upgrade (notmuch)) {
            time_t now = time (NULL);
            struct tm *gm_time = gmtime (&now);