[gvfs/admin-add-copy-push-implementation: 9/9] admin: Add push implementation for better performance




commit 87e8188af60d335582c2c69d23ace2cdc59fa656
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Dec 7 12:13:39 2020 +0100

    admin: Add push implementation for better performance
    
    Copying file from file:// to admin:// is slow. This is because push
    vfunc is not implemented and thus read-write fallback is used. Let's
    implement push to improve performance in this case as well.
    
    https://gitlab.gnome.org/GNOME/gvfs/-/issues/530

 daemon/gvfsbackendadmin.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/daemon/gvfsbackendadmin.c b/daemon/gvfsbackendadmin.c
index 0bb6f9f1..a56e2bd3 100644
--- a/daemon/gvfsbackendadmin.c
+++ b/daemon/gvfsbackendadmin.c
@@ -882,6 +882,40 @@ do_pull (GVfsBackend *backend,
   complete_job (job, error);
 }
 
+static void
+do_push (GVfsBackend *backend,
+         GVfsJobPush *push_job,
+         const char *destination,
+         const char *local_path,
+         GFileCopyFlags flags,
+         gboolean remove_source,
+         GFileProgressCallback progress_callback,
+         gpointer progress_callback_data)
+{
+  GVfsBackendAdmin *self = G_VFS_BACKEND_ADMIN (backend);
+  GVfsJob *job = G_VFS_JOB (push_job);
+  GError *error = NULL;
+  GFile *src_file, *dst_file;
+
+  if (!check_permission (self, job))
+    return;
+
+  src_file = g_file_new_for_path (local_path);
+  dst_file = g_file_new_for_path (destination);
+
+  if (remove_source)
+    g_file_move (src_file, dst_file, flags, job->cancellable,
+                 progress_callback, progress_callback_data, &error);
+  else
+    g_file_copy (src_file, dst_file, flags, job->cancellable,
+                 progress_callback, progress_callback_data, &error);
+
+  g_object_unref (src_file);
+  g_object_unref (dst_file);
+
+  complete_job (job, error);
+}
+
 static void
 do_query_settable_attributes (GVfsBackend *backend,
                               GVfsJobQueryAttributes *query_job,
@@ -1004,6 +1038,7 @@ g_vfs_backend_admin_class_init (GVfsBackendAdminClass * klass)
   backend_class->move = do_move;
   backend_class->copy = do_copy;
   backend_class->pull = do_pull;
+  backend_class->push = do_push;
   backend_class->query_settable_attributes = do_query_settable_attributes;
   backend_class->query_writable_namespaces = do_query_writable_namespaces;
 }


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