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



commit acf63d774ffdff7659294aeaf875badcd4b5d934
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 | 50 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index e288a9afe..29f380495 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -5049,6 +5049,37 @@ get_target_file_for_display_name (GFile       *dir,
     return dest;
 }
 
+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,
+                   _("There was an error getting information about the source."),
+                   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 +5133,13 @@ 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 +5939,17 @@ 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]