[gnome-commander] GnomeCmdPlainPath::get_child - use GIO instead of GnomeVFS



commit b9d3ca4b865bdef0a4cd59b1592445ebb813927f
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sat Mar 20 23:58:35 2021 +0100

    GnomeCmdPlainPath::get_child - use GIO instead of GnomeVFS

 src/gnome-cmd-plain-path.cc | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/gnome-cmd-plain-path.cc b/src/gnome-cmd-plain-path.cc
index 3d15f9f8..debecd39 100644
--- a/src/gnome-cmd-plain-path.cc
+++ b/src/gnome-cmd-plain-path.cc
@@ -50,22 +50,28 @@ GnomeCmdPath *GnomeCmdPlainPath::get_parent()
 
 GnomeCmdPath *GnomeCmdPlainPath::get_child(const gchar *child)
 {
-    GnomeVFSURI *t = gnome_vfs_uri_new (G_DIR_SEPARATOR_S);
-    GnomeVFSURI *u1 = gnome_vfs_uri_append_path (t, path);
-    gnome_vfs_uri_unref (t);
-
-    GnomeVFSURI *u2 = strchr (child, '/')==NULL ?
-                      gnome_vfs_uri_append_file_name (u1, child) :
-                      gnome_vfs_uri_append_path (u1, child);
-    gnome_vfs_uri_unref (u1);
-
-    if (!u2)  return NULL;
-
-    gchar *path_str = gnome_vfs_unescape_string (gnome_vfs_uri_get_path (u2), 0);
-    gnome_vfs_uri_unref (u2);
-
-    GnomeCmdPath *child_path = new GnomeCmdPlainPath(path_str);
-    g_free (path_str);
+    auto fullPath = *path == '/'
+                        ? strchr (child, '/') == nullptr
+                            ? g_strconcat(path, G_DIR_SEPARATOR_S, child, nullptr)
+                            : g_strconcat(path, child, nullptr)
+                        : strchr (child, '/') == nullptr
+                            ? g_strconcat(G_DIR_SEPARATOR_S, path, G_DIR_SEPARATOR_S, child, nullptr)
+                            : g_strconcat(G_DIR_SEPARATOR_S, path, child, nullptr);
+
+    auto childGFile = g_file_new_for_path(fullPath);
+
+    // It could be that in the meantime the file is deleted again.
+    // Therefore we have to check if it really exists.
+    if (!g_file_query_exists (childGFile, nullptr))
+    {
+        g_object_unref(childGFile);
+        return nullptr;
+    }
+    gchar *pathString = g_file_get_path(childGFile);
+    g_object_unref(childGFile);
+
+    GnomeCmdPath *child_path = new GnomeCmdPlainPath(pathString);
+    g_free (pathString);
 
     return child_path;
 }


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