[gnome-commander/issue119: 1/2] Add a separator at the URI path to create a new file in the current directory




commit b60d6bb17eabfd297ce00111723ab1fdae3d040f
Author: Maik Pertermann <maik tapse gmx de>
Date:   Sun Feb 13 19:04:09 2022 +0100

    Add a separator at the URI path to create a new file in the current directory

 src/gnome-cmd-file-selector.cc | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index c5beee5e..69765db4 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -1106,13 +1106,20 @@ static gboolean on_new_textfile_ok (GnomeCmdStringDialog *string_dialog, const g
     GnomeCmdDir *dir = fs->get_directory();
     g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), TRUE);
 
-    GError *error = nullptr;
     auto uriBaseString = static_cast<gchar*>(GNOME_CMD_FILE (dir)->get_uri_str());
+    // Always let the conection URI end with '/' because the last entry should be a directory
+    auto conLastCharacter = uriBaseString[strlen(uriBaseString)-1];
+    auto uriBaseStringsep = conLastCharacter == G_DIR_SEPARATOR
+        ? g_strdup(uriBaseString)
+        : g_strdup_printf("%s%s", uriBaseString, G_DIR_SEPARATOR_S);
+    g_free (uriBaseString);
+
     auto relativeFileNamePath = g_build_filename(".", fname, nullptr);
-    auto uriString = g_uri_resolve_relative (uriBaseString, relativeFileNamePath,
+    GError *error = nullptr;
+    auto uriString = g_uri_resolve_relative (uriBaseStringsep, relativeFileNamePath,
                                              G_URI_FLAGS_NONE, &error);
     g_free(relativeFileNamePath);
-    g_free (uriBaseString);
+    g_free (uriBaseStringsep);
     if (error)
     {
         gnome_cmd_string_dialog_set_error_desc (string_dialog, g_strdup_printf("%s", error->message));


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