[gnome-commander/fix_file_rename_issue] Rename a file or folder with GIO and store the new gFile reference at the same time, fixing #99
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/fix_file_rename_issue] Rename a file or folder with GIO and store the new gFile reference at the same time, fixing #99
- Date: Sat, 13 Mar 2021 21:19:19 +0000 (UTC)
commit 7ba08bbe470dfaa31df90388feb93b7da2a79143
Author: Uwe Scholz <u scholz83 gmx de>
Date: Sat Mar 13 22:17:48 2021 +0100
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 33a9e911..e3aaa739 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]