Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / collect-io.c
index a8d9a7f..8f6b3a2 100644 (file)
@@ -1,16 +1,24 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-
 #include "main.h"
 #include "collect-io.h"
 
@@ -31,7 +39,7 @@
 typedef struct _CollectManagerEntry CollectManagerEntry;
 
 static void collection_load_thumb_step(CollectionData *cd);
-static gint collection_save_private(CollectionData *cd, const gchar *path);
+static gboolean collection_save_private(CollectionData *cd, const gchar *path);
 
 static CollectManagerEntry *collect_manager_get_entry(const gchar *path);
 static void collect_manager_entry_reset(CollectManagerEntry *entry);
@@ -91,11 +99,12 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C
 
        if (!path) path = cd->path;
 
+       pathl = path_from_utf8(path);
+
        DEBUG_1("collection load: append=%d flush=%d only_geometry=%d path=%s",
-                         append, flush, only_geometry, path);
+                         append, flush, only_geometry, pathl);
 
        /* load it */
-       pathl = path_from_utf8(path);
        f = fopen(pathl, "r");
        g_free(pathl);
        if (!f)
@@ -148,6 +157,7 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C
                if (only_geometry) continue;
 
                /* Read filenames */
+               /* TODO: This is not safe! */
                while (*p && *p != '"') p++;
                if (*p) p++;
                buf = p;
@@ -160,7 +170,7 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C
                        if (!flush)
                                changed |= collect_manager_process_action(entry, &buf);
 
-                       valid = (buf[0] == G_DIR_SEPARATOR && collection_add_check(cd, file_data_new_group(buf), FALSE, TRUE));
+                       valid = (buf[0] == G_DIR_SEPARATOR && collection_add_check(cd, file_data_new_simple(buf), FALSE, TRUE));
                        if (!valid) DEBUG_1("collection invalid file: %s", buf);
 
                        total++;
@@ -497,8 +507,14 @@ static void collect_manager_entry_free_data(CollectManagerEntry *entry)
                collect_manager_action_unref(action);
                }
        g_list_free(entry->add_list);
-       g_hash_table_destroy(entry->oldpath_hash);
-       g_hash_table_destroy(entry->newpath_hash);
+       if (g_hash_table_size(entry->oldpath_hash) > 0)
+               g_hash_table_destroy(entry->oldpath_hash);
+       else
+               g_hash_table_unref(entry->oldpath_hash);
+       if (g_hash_table_size(entry->newpath_hash) > 0)
+               g_hash_table_destroy(entry->newpath_hash);
+       else
+               g_hash_table_unref(entry->newpath_hash);
 }
 
 static void collect_manager_entry_init_data(CollectManagerEntry *entry)
@@ -704,6 +720,8 @@ static void collect_manager_refresh(void)
                        else
                                {
                                collect_manager_entry_free(entry);
+
+                               entry = NULL;
                                }
                        }
                }
@@ -725,7 +743,7 @@ static void collect_manager_refresh(void)
 static void collect_manager_process_actions(gint max)
 {
        if (collection_manager_action_list) DEBUG_1("collection manager processing actions");
-       
+
        while (collection_manager_action_list != NULL && max > 0)
                {
                CollectManagerAction *action;
@@ -784,12 +802,11 @@ static void collect_manager_process_actions(gint max)
 static gboolean collect_manager_process_entry(CollectManagerEntry *entry)
 {
        CollectionData *cd;
-       gboolean success;
 
        if (entry->empty) return FALSE;
 
        cd = collection_new(entry->path);
-       success = collection_load_private(cd, entry->path, COLLECTION_LOAD_NONE);
+       (void) collection_load_private(cd, entry->path, COLLECTION_LOAD_NONE);
 
        collection_unref(cd);
 
@@ -935,7 +952,7 @@ void collect_manager_flush(void)
 void collect_manager_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
        if (!(type & NOTIFY_CHANGE) || !fd->change) return;
-       
+
        DEBUG_1("Notify collect_manager: %s %04x", fd->path, type);
        switch (fd->change->type)
                {