if (first == last) {
/* Skip all the dir reading part. */
gchar *filename = g_strdup_printf("%s%s%u", dir, G_DIR_SEPARATOR_S, first);
+ if (is_dir_exist(filename)) {
+ /* a numbered directory with this name exists,
+ * remove the dot-file instead */
+ g_free(filename);
+ filename = g_strdup_printf("%s%s.%u", dir, G_DIR_SEPARATOR_S, first);
+ }
if (claws_unlink(filename) < 0) {
FILE_OP_ERROR(filename, "unlink");
g_free(filename);
while ((dir_name = g_dir_read_name(dp)) != NULL) {
file_no = to_number(dir_name);
if (file_no > 0 && first <= file_no && file_no <= last) {
- if (is_dir_exist(dir_name))
+ if (is_dir_exist(dir_name)) {
+ gchar *dot_file = g_strdup_printf(".%s", dir_name);
+ if (is_file_exist(dot_file) && claws_unlink(dot_file) < 0) {
+ FILE_OP_ERROR(dot_file, "unlink");
+ }
+ g_free(dot_file);
continue;
+ }
if (claws_unlink(dir_name) < 0)
FILE_OP_ERROR(dir_name, "unlink");
}
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 (is_dir_exist(dir_name)) {
+ gchar *dot_file = g_strdup_printf(".%s", dir_name);
+ if (is_file_exist(dot_file) && claws_unlink(dot_file) < 0) {
+ FILE_OP_ERROR(dot_file, "unlink");
+ }
+ g_free(dot_file);
+ continue;
+ }
if (claws_unlink(dir_name) < 0)
FILE_OP_ERROR(dir_name, "unlink");
}
return cnt;
}
-static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+static gchar *imap_get_cached_filename(FolderItem *item, guint msgnum)
{
gchar *path, *filename;
+ cm_return_val_if_fail(item != NULL, NULL);
+
path = folder_item_get_path(item);
if (!is_dir_exist(path)) {
g_free(path);
- return;
+ return NULL;
}
- filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
+ filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msgnum), NULL);
+
+ if (is_dir_exist(filename)) {
+ g_free(filename);
+ filename = g_strconcat(path, G_DIR_SEPARATOR_S, ".", itos(msgnum), NULL);
+ }
g_free(path);
+ return filename;
+}
+
+static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+{
+ gchar *filename;
+
+ filename = imap_get_cached_filename(item, msginfo->msgnum);
+
+ cm_return_if_fail(filename != NULL);
+
if (is_file_exist(filename)) {
claws_unlink(filename);
}
path = folder_item_get_path(item);
if (!is_dir_exist(path))
make_dir_hier(path);
- filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
g_free(path);
+
+ filename = imap_get_cached_filename(item, uid);
debug_print("trying to fetch cached %s\n", filename);
+
if (is_file_exist(filename)) {
/* see whether the local file represents the whole message
* or not. As the IMAP server reports size with \r chars,
static gboolean imap_is_msg_fully_cached(Folder *folder, FolderItem *item, gint uid)
{
- gchar *path, *filename;
+ gchar *filename;
guint size = 0;
MsgInfo *cached = msgcache_get_msg(item->cache,uid);
procmsg_msginfo_free(cached);
return TRUE;
}
- path = folder_item_get_path(item);
- if (!is_dir_exist(path)) {
- g_free(path);
- return FALSE;
- }
- filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
- g_free(path);
+ filename = imap_get_cached_filename(item, uid);
+
if (is_file_exist(filename)) {
if (cached && cached->total_size == cached->size) {
/* fast path */