[gnome-commander] Close remote connections with _mount_unmount_with_operation, fixing #19



commit b4ff6ba4ce972d75186cb31afe163d922c7e518c
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sun Nov 7 18:53:03 2021 +0100

    Close remote connections with _mount_unmount_with_operation, fixing #19

 NEWS                        |  1 +
 doc/C/releases.xml          |  3 +++
 src/gnome-cmd-con-remote.cc | 45 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index c68f2798..d15b1f2a 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Bug fixes:
  * Fixed issue #3  (Mounted devices pluged when Commander is running are not noticed)
  * Fixed issue #5  ("Follow Links" option does not work when copying files)
  * Fixed issue #16 (Start-left-dir doesn't work on '.' (dot directory))
+ * Fixed issue #19 (FTP connections are not closed correctly)
  * Fixed issue #33 (Get rid of deprecated gnome-vfs)
  * Fixed issue #52 (Auto refresh when changing permissions etc)
  * Fixed issue #75 (Newly inserted DVD does not show up)
diff --git a/doc/C/releases.xml b/doc/C/releases.xml
index 1c1c57ff..3d37133c 100644
--- a/doc/C/releases.xml
+++ b/doc/C/releases.xml
@@ -38,6 +38,9 @@
                         <listitem>
                             <para>Fixed issue #16 (Start-left-dir doesn't work on '.' (dot directory))</para>
                         </listitem>
+                        <listitem>
+                            <para>Fixed issue #19 (FTP connections are not closed correctly)</para>
+                        </listitem>
                         <listitem>
                             <para>Fixed issue #33 (Get rid of deprecated gnome-vfs)</para>
                         </listitem>
diff --git a/src/gnome-cmd-con-remote.cc b/src/gnome-cmd-con-remote.cc
index f8f2ecfd..376a0078 100644
--- a/src/gnome-cmd-con-remote.cc
+++ b/src/gnome-cmd-con-remote.cc
@@ -103,13 +103,54 @@ static void remote_open (GnomeCmdCon *con)
 }
 
 
+static void remote_close_callback(GObject *gobj, GAsyncResult *result, gpointer user_data)
+{
+    auto gMount = (GMount*) gobj;
+    auto con = (GnomeCmdCon*) user_data;
+    GError *error = nullptr;
+
+    g_mount_unmount_with_operation_finish(gMount, result, &error);
+
+    if (error)
+    {
+        gnome_cmd_error_message(_("Disconnect error"), error);
+        return;
+    }
+
+    con->state = GnomeCmdCon::STATE_CLOSED;
+    con->open_result = GnomeCmdCon::OPEN_NOT_STARTED;
+}
+
 static gboolean remote_close (GnomeCmdCon *con)
 {
+    GError *error = nullptr;
+
     gnome_cmd_con_set_default_dir (con, nullptr);
     delete con->base_path;
     con->base_path = nullptr;
-    con->state = GnomeCmdCon::STATE_CLOSED;
-    con->open_result = GnomeCmdCon::OPEN_NOT_STARTED;
+
+    auto uri = gnome_cmd_con_get_uri(con);
+    auto gFileTmp = g_file_new_for_uri(uri);
+    DEBUG ('m', "Closing connection to %s\n", uri);
+
+    auto gMount = g_file_find_enclosing_mount (gFileTmp, nullptr, &error);
+    if (error)
+    {
+        g_warning("remote_close - g_file_find_enclosing_mount error: %s", error->message);
+        g_error_free(error);
+        return false;
+    }
+
+    g_mount_unmount_with_operation (
+        gMount,
+        G_MOUNT_UNMOUNT_NONE,
+        nullptr,
+        nullptr,
+        remote_close_callback,
+        con
+    );
+
+    g_object_unref(gFileTmp);
 
     return TRUE;
 }


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