talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 17c095ce57618dcf63dc3c64555c90067be7fadd
parent 19209ab1da44f33fe370f6f54ed2dd85912bb50b
Author: Colin Leroy <colin@colino.net>
Date:   Wed, 14 May 2014 10:19:45 +0200

Fix remove_numbered_files_not_in_list doing exactly not what it said.

Diffstat:
Msrc/common/utils.c | 26+++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/common/utils.c b/src/common/utils.c @@ -2403,7 +2403,8 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist) const gchar *dir_name; gchar *prev_dir; gint file_no; - GHashTable *file_no_tbl; + GHashTable *wanted_files; + GSList *cur; if (numberlist == NULL) return 0; @@ -2422,26 +2423,25 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist) return -1; } - file_no_tbl = g_hash_table_new(g_direct_hash, g_direct_equal); + wanted_files = g_hash_table_new(g_direct_hash, g_direct_equal); + for (cur = numberlist; cur != NULL; cur = cur->next) { + /* numberlist->data is expected to be GINT_TO_POINTER */ + g_hash_table_insert(wanted_files, numberlist->data, GINT_TO_POINTER(1)); + } + while ((dir_name = g_dir_read_name(dp)) != NULL) { file_no = to_number(dir_name); if (is_dir_exist(dir_name)) - continue; - if (file_no > 0) - g_hash_table_insert(file_no_tbl, GINT_TO_POINTER(file_no), GINT_TO_POINTER(1)); - } - - do { - if (g_hash_table_lookup(file_no_tbl, numberlist->data) == NULL) { - debug_print("removing unwanted file %d from %s\n", - GPOINTER_TO_INT(numberlist->data), dir); + continue; + if (file_no > 0 && g_hash_table_lookup(wanted_files, GINT_TO_POINTER(file_no)) == NULL) { + debug_print("removing unwanted file %d from %s\n", file_no, dir); if (claws_unlink(dir_name) < 0) FILE_OP_ERROR(dir_name, "unlink"); } - } while ((numberlist = g_slist_next(numberlist))); + } g_dir_close(dp); - g_hash_table_destroy(file_no_tbl); + g_hash_table_destroy(wanted_files); if (g_chdir(prev_dir) < 0) { FILE_OP_ERROR(prev_dir, "chdir");