mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-01-03 15:21:41 +01:00
new: Cleanup. De-duplicate file name removal code.
Previously, file name removal was implemented identically in two places. Now it's captured in one function. This is important because file name removal is about to get slightly more complicated with eager tag synchronization and correct removal atomicity.
This commit is contained in:
parent
1353dbe864
commit
191c4ae693
1 changed files with 17 additions and 12 deletions
|
@ -724,6 +724,21 @@ upgrade_print_progress (void *closure,
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remove one message filename from the database. */
|
||||||
|
static notmuch_status_t
|
||||||
|
remove_filename (notmuch_database_t *notmuch,
|
||||||
|
const char *path,
|
||||||
|
add_files_state_t *add_files_state)
|
||||||
|
{
|
||||||
|
notmuch_status_t status;
|
||||||
|
status = notmuch_database_remove_message (notmuch, path);
|
||||||
|
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
||||||
|
add_files_state->renamed_messages++;
|
||||||
|
else
|
||||||
|
add_files_state->removed_messages++;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/* Recursively remove all filenames from the database referring to
|
/* Recursively remove all filenames from the database referring to
|
||||||
* 'path' (or to any of its children). */
|
* 'path' (or to any of its children). */
|
||||||
static void
|
static void
|
||||||
|
@ -734,7 +749,6 @@ _remove_directory (void *ctx,
|
||||||
{
|
{
|
||||||
notmuch_directory_t *directory;
|
notmuch_directory_t *directory;
|
||||||
notmuch_filenames_t *files, *subdirs;
|
notmuch_filenames_t *files, *subdirs;
|
||||||
notmuch_status_t status;
|
|
||||||
char *absolute;
|
char *absolute;
|
||||||
|
|
||||||
directory = notmuch_database_get_directory (notmuch, path);
|
directory = notmuch_database_get_directory (notmuch, path);
|
||||||
|
@ -745,11 +759,7 @@ _remove_directory (void *ctx,
|
||||||
{
|
{
|
||||||
absolute = talloc_asprintf (ctx, "%s/%s", path,
|
absolute = talloc_asprintf (ctx, "%s/%s", path,
|
||||||
notmuch_filenames_get (files));
|
notmuch_filenames_get (files));
|
||||||
status = notmuch_database_remove_message (notmuch, absolute);
|
remove_filename (notmuch, absolute, add_files_state);
|
||||||
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
|
||||||
add_files_state->renamed_messages++;
|
|
||||||
else
|
|
||||||
add_files_state->removed_messages++;
|
|
||||||
talloc_free (absolute);
|
talloc_free (absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -780,7 +790,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
char *dot_notmuch_path;
|
char *dot_notmuch_path;
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
_filename_node_t *f;
|
_filename_node_t *f;
|
||||||
notmuch_status_t status;
|
|
||||||
int i;
|
int i;
|
||||||
notmuch_bool_t timer_is_active = FALSE;
|
notmuch_bool_t timer_is_active = FALSE;
|
||||||
|
|
||||||
|
@ -869,11 +878,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
|
|
||||||
gettimeofday (&tv_start, NULL);
|
gettimeofday (&tv_start, NULL);
|
||||||
for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
|
for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
|
||||||
status = notmuch_database_remove_message (notmuch, f->filename);
|
remove_filename (notmuch, f->filename, &add_files_state);
|
||||||
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
|
||||||
add_files_state.renamed_messages++;
|
|
||||||
else
|
|
||||||
add_files_state.removed_messages++;
|
|
||||||
if (do_print_progress) {
|
if (do_print_progress) {
|
||||||
do_print_progress = 0;
|
do_print_progress = 0;
|
||||||
generic_print_progress ("Cleaned up", "messages",
|
generic_print_progress ("Cleaned up", "messages",
|
||||||
|
|
Loading…
Reference in a new issue