[gnome-commander] Allow to cache each item with its URI



commit 3be800cdb3736bd4417139e432159c6ef22d9d55
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sat Sep 18 22:17:35 2021 +0200

    Allow to cache each item with its URI

 src/gnome-cmd-con.cc |  9 ++++++---
 src/gnome-cmd-con.h  |  2 +-
 src/gnome-cmd-dir.cc | 13 +++++++------
 3 files changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/src/gnome-cmd-con.cc b/src/gnome-cmd-con.cc
index c68ad0ab..2329f854 100644
--- a/src/gnome-cmd-con.cc
+++ b/src/gnome-cmd-con.cc
@@ -542,14 +542,17 @@ gboolean gnome_cmd_con_mkdir (GnomeCmdCon *con, const gchar *path_str, GError *e
 }
 
 
-void gnome_cmd_con_add_to_cache (GnomeCmdCon *con, GnomeCmdDir *dir)
+void gnome_cmd_con_add_to_cache (GnomeCmdCon *con, GnomeCmdDir *dir, gchar *uri_str)
 {
     g_return_if_fail (GNOME_CMD_IS_CON (con));
     g_return_if_fail (GNOME_CMD_IS_DIR (dir));
 
-    gchar *uri_str = GNOME_CMD_FILE (dir)->get_uri_str();
+    if (!uri_str)
+    {
+        uri_str = GNOME_CMD_FILE (dir)->get_uri_str();
+    }
 
-    if (uri_str == nullptr)
+    if (!uri_str)
     {
         return;
     }
diff --git a/src/gnome-cmd-con.h b/src/gnome-cmd-con.h
index ec83da39..3c6d7c24 100644
--- a/src/gnome-cmd-con.h
+++ b/src/gnome-cmd-con.h
@@ -345,7 +345,7 @@ gboolean gnome_cmd_con_get_path_target_type (GnomeCmdCon *con, const gchar *path
 
 gboolean gnome_cmd_con_mkdir (GnomeCmdCon *con, const gchar *path_str, GError *error);
 
-void gnome_cmd_con_add_to_cache (GnomeCmdCon *con, GnomeCmdDir *dir);
+void gnome_cmd_con_add_to_cache (GnomeCmdCon *con, GnomeCmdDir *dir, gchar *uri_str = nullptr);
 
 void gnome_cmd_con_remove_from_cache (GnomeCmdCon *con, GnomeCmdDir *dir);
 
diff --git a/src/gnome-cmd-dir.cc b/src/gnome-cmd-dir.cc
index a3578e10..874cc074 100644
--- a/src/gnome-cmd-dir.cc
+++ b/src/gnome-cmd-dir.cc
@@ -256,13 +256,13 @@ GnomeCmdDir *gnome_cmd_dir_new_from_gfileinfo (GFileInfo *gFileInfo, GnomeCmdDir
     auto uriString = g_file_get_uri (gFile);
 
     GnomeCmdDir *dir = gnome_cmd_con_cache_lookup (gnome_cmd_dir_get_connection (parent), uriString);
-    g_free (uriString);
     g_object_unref (gFile);
 
     if (dir)
     {
         delete path;
         GNOME_CMD_FILE (dir)->update_gFileInfo(gFileInfo);
+        g_free (uriString);
         return dir;
     }
 
@@ -273,7 +273,7 @@ GnomeCmdDir *gnome_cmd_dir_new_from_gfileinfo (GFileInfo *gFileInfo, GnomeCmdDir
     gnome_cmd_dir_set_path (dir, path);
     dir->priv->needs_mtime_update = FALSE;
 
-    gnome_cmd_con_add_to_cache (gnome_cmd_dir_get_connection (parent), dir);
+    gnome_cmd_con_add_to_cache (gnome_cmd_dir_get_connection (parent), dir, uriString);
 
     return dir;
 }
@@ -288,11 +288,11 @@ GnomeCmdDir *gnome_cmd_dir_new_with_con (GnomeCmdCon *con)
     auto uri_str = g_file_get_uri(gFile);
     g_object_unref (gFile);
     GnomeCmdDir *dir = gnome_cmd_con_cache_lookup (con, uri_str);
-    g_free (uri_str);
 
     if (dir)
     {
         GNOME_CMD_FILE (dir)->update_gFileInfo(con->base_gFileInfo);
+        g_free (uri_str);
         return dir;
     }
 
@@ -303,7 +303,7 @@ GnomeCmdDir *gnome_cmd_dir_new_with_con (GnomeCmdCon *con)
     dir->priv->con = con;
     dir->priv->needs_mtime_update = FALSE;
 
-    gnome_cmd_con_add_to_cache (con, dir);
+    gnome_cmd_con_add_to_cache (con, dir, uri_str);
 
     return dir;
 }
@@ -322,9 +322,9 @@ GnomeCmdDir *gnome_cmd_dir_new (GnomeCmdCon *con, GnomeCmdPath *path, gboolean i
     g_object_unref (gFile);
 
     GnomeCmdDir *dir = gnome_cmd_con_cache_lookup (con, uriString);
-    g_free (uriString);
     if (dir)
     {
+        g_free (uriString);
         return dir;
     }
 
@@ -339,6 +339,7 @@ GnomeCmdDir *gnome_cmd_dir_new (GnomeCmdCon *con, GnomeCmdPath *path, gboolean i
             gnome_cmd_show_message (*main_win, path->get_display_path(), error->message);
             g_error_free(error);
         }
+        g_free (uriString);
         return nullptr;
     }
 
@@ -349,7 +350,7 @@ GnomeCmdDir *gnome_cmd_dir_new (GnomeCmdCon *con, GnomeCmdPath *path, gboolean i
     dir->priv->con = con;
     dir->priv->needs_mtime_update = FALSE;
 
-    gnome_cmd_con_add_to_cache (con, dir);
+    gnome_cmd_con_add_to_cache (con, dir, uriString);
 
     return dir;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]