mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-01-18 17:25:57 +01:00
new: Cleanup. Put removed/renamed message count in add_files_state_t.
Previously, pointers to these variables were passed around individually. This was okay when only one function needed them, but we're about to need them in a few more places.
This commit is contained in:
parent
51c3c0b2d2
commit
1353dbe864
1 changed files with 16 additions and 20 deletions
|
@ -42,7 +42,7 @@ typedef struct {
|
||||||
|
|
||||||
int total_files;
|
int total_files;
|
||||||
int processed_files;
|
int processed_files;
|
||||||
int added_messages;
|
int added_messages, removed_messages, renamed_messages;
|
||||||
struct timeval tv_start;
|
struct timeval tv_start;
|
||||||
|
|
||||||
_filename_list_t *removed_files;
|
_filename_list_t *removed_files;
|
||||||
|
@ -730,8 +730,7 @@ static void
|
||||||
_remove_directory (void *ctx,
|
_remove_directory (void *ctx,
|
||||||
notmuch_database_t *notmuch,
|
notmuch_database_t *notmuch,
|
||||||
const char *path,
|
const char *path,
|
||||||
int *renamed_files,
|
add_files_state_t *add_files_state)
|
||||||
int *removed_files)
|
|
||||||
{
|
{
|
||||||
notmuch_directory_t *directory;
|
notmuch_directory_t *directory;
|
||||||
notmuch_filenames_t *files, *subdirs;
|
notmuch_filenames_t *files, *subdirs;
|
||||||
|
@ -748,9 +747,9 @@ _remove_directory (void *ctx,
|
||||||
notmuch_filenames_get (files));
|
notmuch_filenames_get (files));
|
||||||
status = notmuch_database_remove_message (notmuch, absolute);
|
status = notmuch_database_remove_message (notmuch, absolute);
|
||||||
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
||||||
*renamed_files = *renamed_files + 1;
|
add_files_state->renamed_messages++;
|
||||||
else
|
else
|
||||||
*removed_files = *removed_files + 1;
|
add_files_state->removed_messages++;
|
||||||
talloc_free (absolute);
|
talloc_free (absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,7 +759,7 @@ _remove_directory (void *ctx,
|
||||||
{
|
{
|
||||||
absolute = talloc_asprintf (ctx, "%s/%s", path,
|
absolute = talloc_asprintf (ctx, "%s/%s", path,
|
||||||
notmuch_filenames_get (subdirs));
|
notmuch_filenames_get (subdirs));
|
||||||
_remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);
|
_remove_directory (ctx, notmuch, absolute, add_files_state);
|
||||||
talloc_free (absolute);
|
talloc_free (absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,7 +780,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;
|
||||||
int renamed_files, removed_files;
|
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
int i;
|
int i;
|
||||||
notmuch_bool_t timer_is_active = FALSE;
|
notmuch_bool_t timer_is_active = FALSE;
|
||||||
|
@ -854,6 +852,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
|
|
||||||
add_files_state.processed_files = 0;
|
add_files_state.processed_files = 0;
|
||||||
add_files_state.added_messages = 0;
|
add_files_state.added_messages = 0;
|
||||||
|
add_files_state.removed_messages = add_files_state.renamed_messages = 0;
|
||||||
gettimeofday (&add_files_state.tv_start, NULL);
|
gettimeofday (&add_files_state.tv_start, NULL);
|
||||||
|
|
||||||
add_files_state.removed_files = _filename_list_create (ctx);
|
add_files_state.removed_files = _filename_list_create (ctx);
|
||||||
|
@ -868,27 +867,24 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
|
|
||||||
ret = add_files (notmuch, db_path, &add_files_state);
|
ret = add_files (notmuch, db_path, &add_files_state);
|
||||||
|
|
||||||
removed_files = 0;
|
|
||||||
renamed_files = 0;
|
|
||||||
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);
|
status = notmuch_database_remove_message (notmuch, f->filename);
|
||||||
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
|
||||||
renamed_files++;
|
add_files_state.renamed_messages++;
|
||||||
else
|
else
|
||||||
removed_files++;
|
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",
|
||||||
tv_start, removed_files + renamed_files,
|
tv_start, add_files_state.removed_messages + add_files_state.renamed_messages,
|
||||||
add_files_state.removed_files->count);
|
add_files_state.removed_files->count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday (&tv_start, NULL);
|
gettimeofday (&tv_start, NULL);
|
||||||
for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
|
for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
|
||||||
_remove_directory (ctx, notmuch, f->filename,
|
_remove_directory (ctx, notmuch, f->filename, &add_files_state);
|
||||||
&renamed_files, &removed_files);
|
|
||||||
if (do_print_progress) {
|
if (do_print_progress) {
|
||||||
do_print_progress = 0;
|
do_print_progress = 0;
|
||||||
generic_print_progress ("Cleaned up", "directories",
|
generic_print_progress ("Cleaned up", "directories",
|
||||||
|
@ -965,16 +961,16 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
|
||||||
printf ("No new mail.");
|
printf ("No new mail.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed_files) {
|
if (add_files_state.removed_messages) {
|
||||||
printf (" Removed %d %s.",
|
printf (" Removed %d %s.",
|
||||||
removed_files,
|
add_files_state.removed_messages,
|
||||||
removed_files == 1 ? "message" : "messages");
|
add_files_state.removed_messages == 1 ? "message" : "messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renamed_files) {
|
if (add_files_state.renamed_messages) {
|
||||||
printf (" Detected %d file %s.",
|
printf (" Detected %d file %s.",
|
||||||
renamed_files,
|
add_files_state.renamed_messages,
|
||||||
renamed_files == 1 ? "rename" : "renames");
|
add_files_state.renamed_messages == 1 ? "rename" : "renames");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
Loading…
Reference in a new issue