[nautilus/wip/oholy/google-drive-conflict-dialog] file-operations: Fix conflict dialog for google-drive



commit 93140286dc75d22beb9fe918c96c2e54ba449f63
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Jan 31 13:46:40 2020 +0100

    file-operations: Fix conflict dialog for google-drive
    
    Conflict dialog doesn't work properly for google-drive files, because
    G_IO_ERROR_EXISTS can be returned even if a destination file based on
    a basename of a source file doesn't exists. This happens when a destination
    directory already contains some file with the same display_name as the
    source file has. Usually, display_name is based on filename, but google-drive
    is not traditional filesystem and uses unique IDs for files. Although,
    google-drive supports multiple files with the same display_bane in one folder,
    the copy and move operations behave traditionally and tries to overwrite
    existing files with the same title. Let's base the destination file on
    display_name for google-drive to fix issues with the conflict dialog.
    
    See: https://gitlab.gnome.org/GNOME/gvfs/merge_requests/58

 src/nautilus-file-operations.c | 60 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index e288a9afe..0c9babb1a 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -5049,6 +5049,43 @@ get_target_file_for_display_name (GFile       *dir,
     return dest;
 }
 
+/* This is a workaround to resolve broken conflict dialog for google-drive
+ * locations. This is needed to provide POSIX-like behavior for google-drive
+ * filesystem, where each file has an unique identificator that is not tied to
+ * its display_name. See the following MR for more details:
+ * https://gitlab.gnome.org/GNOME/nautilus/merge_requests/514.
+ */
+static GFile *
+get_target_file_from_source_display_name (CommonJob *job,
+                                          GFile     *src,
+                                          GFile     *dir)
+{
+    g_autoptr (GError) error = NULL;
+    g_autoptr (GFileInfo) info = NULL;
+    GFile *dest = NULL;
+
+    info = g_file_query_info (src, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, &error);
+    if (info == NULL)
+    {
+        run_error (job,
+                   g_strdup (_("There was an error getting information about the source.")),
+                   g_strdup (error->message),
+                   NULL,
+                   FALSE,
+                   CANCEL,
+                   NULL);
+
+        abort_job (job);
+    }
+    else
+    {
+        dest = get_target_file_for_display_name (dir, g_file_info_get_display_name (info));
+    }
+
+    return dest;
+}
+
+
 /* Debuting files is non-NULL only for toplevel items */
 static void
 copy_move_file (CopyMoveJob   *copy_job,
@@ -5102,6 +5139,15 @@ copy_move_file (CopyMoveJob   *copy_job,
         dest = get_target_file_with_custom_name (src, dest_dir, *dest_fs_type, same_fs,
                                                  copy_job->target_name);
     }
+    else if (g_file_has_uri_scheme (src, "google-drive") &&
+             g_file_has_uri_scheme (dest_dir, "google-drive"))
+    {
+        dest = get_target_file_from_source_display_name (job, src, dest_dir);
+        if (dest == NULL)
+        {
+            return;
+        }
+    }
     else
     {
         dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
@@ -5901,7 +5947,19 @@ move_file_prepare (CopyMoveJob  *move_job,
 
     job = (CommonJob *) move_job;
 
-    dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+    if (g_file_has_uri_scheme (src, "google-drive") &&
+        g_file_has_uri_scheme (dest_dir, "google-drive"))
+    {
+        dest = get_target_file_from_source_display_name (job, src, dest_dir);
+        if (dest == NULL)
+        {
+            return;
+        }
+    }
+    else
+    {
+        dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+    }
 
 
     /* Don't allow recursive move/copy into itself.


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