mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-01-18 17:25:57 +01:00
notmuch new: Fix deletion support to recurse on removed directories.
Previously, when notmuch detected that a directory had been deleted it was only removing files immediately in that directory. We now correctly recurse to also remove any directories (and files, etc.) within sub-directories, etc.
This commit is contained in:
parent
cb8e4bc9c0
commit
21f8fd6967
1 changed files with 45 additions and 22 deletions
|
@ -616,6 +616,49 @@ count_files (const char *path, int *count)
|
||||||
free (fs_entries);
|
free (fs_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Recursively remove all filenames from the database referring to
|
||||||
|
* 'path' (or to any of its children). */
|
||||||
|
static void
|
||||||
|
_remove_directory (void *ctx,
|
||||||
|
notmuch_database_t *notmuch,
|
||||||
|
const char *path,
|
||||||
|
int *renamed_files,
|
||||||
|
int *removed_files)
|
||||||
|
{
|
||||||
|
notmuch_directory_t *directory;
|
||||||
|
notmuch_filenames_t *files, *subdirs;
|
||||||
|
notmuch_status_t status;
|
||||||
|
char *absolute;
|
||||||
|
|
||||||
|
directory = notmuch_database_get_directory (notmuch, path);
|
||||||
|
|
||||||
|
for (files = notmuch_directory_get_child_files (directory);
|
||||||
|
notmuch_filenames_has_more (files);
|
||||||
|
notmuch_filenames_advance (files))
|
||||||
|
{
|
||||||
|
absolute = talloc_asprintf (ctx, "%s/%s", path,
|
||||||
|
notmuch_filenames_get (files));
|
||||||
|
status = notmuch_database_remove_message (notmuch, absolute);
|
||||||
|
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
||||||
|
*renamed_files = *renamed_files + 1;
|
||||||
|
else
|
||||||
|
*removed_files = *removed_files + 1;
|
||||||
|
talloc_free (absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (subdirs = notmuch_directory_get_child_directories (directory);
|
||||||
|
notmuch_filenames_has_more (subdirs);
|
||||||
|
notmuch_filenames_advance (subdirs))
|
||||||
|
{
|
||||||
|
absolute = talloc_asprintf (ctx, "%s/%s", path,
|
||||||
|
notmuch_filenames_get (subdirs));
|
||||||
|
_remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);
|
||||||
|
talloc_free (absolute);
|
||||||
|
}
|
||||||
|
|
||||||
|
notmuch_directory_destroy (directory);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
notmuch_new_command (void *ctx, int argc, char *argv[])
|
notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -704,28 +747,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
for (f = add_files_state.removed_directories->head; f; f = f->next) {
|
for (f = add_files_state.removed_directories->head; f; f = f->next) {
|
||||||
notmuch_directory_t *directory;
|
_remove_directory (ctx, notmuch, f->filename,
|
||||||
notmuch_filenames_t *files;
|
&renamed_files, &removed_files);
|
||||||
|
|
||||||
directory = notmuch_database_get_directory (notmuch, f->filename);
|
|
||||||
|
|
||||||
for (files = notmuch_directory_get_child_files (directory);
|
|
||||||
notmuch_filenames_has_more (files);
|
|
||||||
notmuch_filenames_advance (files))
|
|
||||||
{
|
|
||||||
char *absolute;
|
|
||||||
|
|
||||||
absolute = talloc_asprintf (ctx, "%s/%s", f->filename,
|
|
||||||
notmuch_filenames_get (files));
|
|
||||||
status = notmuch_database_remove_message (notmuch, absolute);
|
|
||||||
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
|
||||||
renamed_files++;
|
|
||||||
else
|
|
||||||
removed_files++;
|
|
||||||
talloc_free (absolute);
|
|
||||||
}
|
|
||||||
|
|
||||||
notmuch_directory_destroy (directory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
talloc_free (add_files_state.removed_files);
|
talloc_free (add_files_state.removed_files);
|
||||||
|
|
Loading…
Reference in a new issue