[gnome-commander] Fix move of directory when it is sitting on a remote



commit e1191dcce4e1b514970ed7f67714e75a4fee4736
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sun Mar 27 20:30:53 2022 +0200

    Fix move of directory when it is sitting on a remote

 src/gnome-cmd-con-list.cc | 22 ++++++++++++++++++++++
 src/gnome-cmd-con-list.h  |  2 ++
 src/gnome-cmd-xfer.cc     | 28 +++++++++++++++++++++++++---
 3 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/src/gnome-cmd-con-list.cc b/src/gnome-cmd-con-list.cc
index e3a5ca0a..5cd71269 100644
--- a/src/gnome-cmd-con-list.cc
+++ b/src/gnome-cmd-con-list.cc
@@ -385,3 +385,25 @@ GnomeCmdCon *GnomeCmdConList::get_smb()
     return priv->smb_con;
 }
 #endif
+
+
+GnomeCmdCon *get_remote_con_for_gfile(GFile *gFile)
+{
+    GnomeCmdCon *gnomeCmdCon = nullptr;
+    auto remoteCons = get_remote_cons();
+
+    for(auto remoteConEntry = remoteCons; remoteConEntry; remoteConEntry = remoteConEntry->next)
+    {
+        auto remoteCon = static_cast<GnomeCmdConRemote*>(remoteConEntry->data);
+        auto gnomeCmdConParent = &remoteCon->parent;
+        auto gFileSrcUri = g_file_get_uri(gFile);
+        if (strstr(gFileSrcUri, gnomeCmdConParent->uri))
+        {
+            gnomeCmdCon = gnomeCmdConParent;
+            g_free(gFileSrcUri);
+            break;
+        }
+        g_free(gFileSrcUri);
+    }
+    return gnomeCmdCon;
+}
\ No newline at end of file
diff --git a/src/gnome-cmd-con-list.h b/src/gnome-cmd-con-list.h
index 6e1101c1..0a7a962d 100644
--- a/src/gnome-cmd-con-list.h
+++ b/src/gnome-cmd-con-list.h
@@ -115,3 +115,5 @@ inline GList *get_remote_cons ()
 {
     return gnome_cmd_con_list_get_all_remote (gnome_cmd_con_list_get ());
 }
+
+GnomeCmdCon *get_remote_con_for_gfile(GFile *gFile);
\ No newline at end of file
diff --git a/src/gnome-cmd-xfer.cc b/src/gnome-cmd-xfer.cc
index a583b651..80e923ae 100644
--- a/src/gnome-cmd-xfer.cc
+++ b/src/gnome-cmd-xfer.cc
@@ -1111,8 +1111,30 @@ gnome_cmd_move_gfile_recursive (GFile *srcGFile,
                     g_object_unref(gFileInfo);
                     return false;
                 }
-                auto gFileParentPath = g_file_get_path(srcGFileParent);
-                auto gnomeCmdDirParent = gnome_cmd_dir_new (get_home_con(), new 
GnomeCmdPlainPath(gFileParentPath));
+
+                GnomeCmdDir *gnomeCmdDirParent = nullptr;
+                GnomeCmdCon *gnomeCmdCon = nullptr;
+                auto srcUriSchema = g_file_get_uri_scheme(srcGFileParent);
+                if (strcmp(srcUriSchema, "file") && (strcmp(srcUriSchema, "smb")))
+                {
+                    gnomeCmdCon = get_remote_con_for_gfile(srcGFileParent);
+                    if (gnomeCmdCon)
+                    {
+                        auto gFileParentUri = g_file_get_uri(srcGFileParent);
+                        auto gUriParent = g_uri_parse(gFileParentUri, G_URI_FLAGS_NONE, nullptr);
+                        auto gFileParentPathFromUri = g_uri_get_path(gUriParent);
+                        gnomeCmdDirParent = gnome_cmd_dir_new (gnomeCmdCon, new 
GnomeCmdPlainPath(gFileParentPathFromUri));
+                        g_free(gFileParentUri);
+                    }
+                }
+                else if (strcmp(srcUriSchema, "file"))
+                {
+                    auto gFileParentPath = g_file_get_path(srcGFileParent);
+                    gnomeCmdCon = get_home_con();
+                    gnomeCmdDirParent = gnome_cmd_dir_new (gnomeCmdCon, new 
GnomeCmdPlainPath(gFileParentPath));
+                    g_free(gFileParentPath);
+                }
+
                 auto gnomeCmdDir = gnome_cmd_dir_new_from_gfileinfo(gFileInfo, gnomeCmdDirParent);
 
                 auto deleteData = g_new0 (DeleteData, 1);
@@ -1120,8 +1142,8 @@ gnome_cmd_move_gfile_recursive (GFile *srcGFile,
                 deleteData->originAction = DeleteData::OriginAction::MOVE;
                 do_delete (deleteData, false); // false -> do not show progress window
 
-                g_free(gFileParentPath);
                 g_object_unref(srcGFileParent);
+                g_free(srcUriSchema);
             }
             else
             {


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