[gnome-commander/cherry-pick-dd90e65a] Merge branch 'fix_file_rename_issue' into 'gcmd-1-12'




commit c41d64979fd40c1e668a3aea6b0482ac5b504735
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sat Mar 13 21:22:41 2021 +0000

    Merge branch 'fix_file_rename_issue' into 'gcmd-1-12'
    
    Rename a file or folder with GIO and store the new gFile reference at the same time, fixing #99
    
    See merge request GNOME/gnome-commander!8
    
    (cherry picked from commit dd90e65ac33154b5a9225290a209d170196fb376)
    
    7ba08bbe Rename a file or folder with GIO and store the new gFile reference at the same time, fixing #99

 src/gnome-cmd-file.cc | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index dafbc910..a69d23ae 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -354,18 +354,27 @@ GnomeVFSResult GnomeCmdFile::rename(const gchar *new_name)
 
     new_info->name = const_cast<gchar *> (new_name);
 
-    GnomeVFSURI *uri = get_uri();
-    GnomeVFSResult result = gnome_vfs_set_file_info_uri (uri, new_info, GNOME_VFS_SET_FILE_INFO_NAME);
-    gnome_vfs_uri_unref (uri);
+    GError *error;
+    error = nullptr;
+
+    auto newgFile = g_file_set_display_name (this->gFile, new_name, nullptr, &error);
 
-    if (result==GNOME_VFS_OK)       //  re-read GnomeVFSFileInfo for the new MIME type
+    if (error || newgFile == nullptr)
     {
-        const GnomeVFSFileInfoOptions infoOpts = (GnomeVFSFileInfoOptions) 
(GNOME_VFS_FILE_INFO_FOLLOW_LINKS|GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
-        uri = get_uri(new_name);
-        result = gnome_vfs_get_file_info_uri (uri, new_info, infoOpts);
-        gnome_vfs_uri_unref (uri);
+        g_message ("rename to \"%s\" failed: %s", new_name, error->message);
+        g_error_free (error);
+        return GNOME_VFS_OK;
     }
 
+    g_object_unref(this->gFile);
+    this->gFile = newgFile;
+
+    // TODO: Remove the following when GnomeVFS->GIO migration is done
+    const GnomeVFSFileInfoOptions infoOpts = (GnomeVFSFileInfoOptions) 
(GNOME_VFS_FILE_INFO_FOLLOW_LINKS|GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
+    auto newUri = get_uri(new_name);
+    auto result = gnome_vfs_get_file_info_uri (newUri, new_info, infoOpts);
+    gnome_vfs_uri_unref (newUri);
+
     if (result==GNOME_VFS_OK && has_parent_dir (this))
     {
         gchar *old_uri_str = get_uri_str();


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