0005-admin-Ensure-correct-ownership-when-moving-to-file-uri.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From d5dfd823c94045488aef8727c553f1e0f7666b90 Mon Sep 17 00:00:00 2001
  2. From: Ondrej Holy <oholy@redhat.com>
  3. Date: Fri, 24 May 2019 09:43:43 +0200
  4. Subject: [PATCH] admin: Ensure correct ownership when moving to file:// uri
  5. User and group is not restored properly when moving (or copying with
  6. G_FILE_COPY_ALL_METADATA) from admin:// to file://, because it is handled
  7. by GIO fallback code, which doesn't run with root permissions. Let's
  8. handle this case with pull method to ensure correct ownership.
  9. [Retrieved from:
  10. https://gitlab.gnome.org/GNOME/gvfs/commit/d5dfd823c94045488aef8727c553f1e0f7666b90]
  11. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  12. ---
  13. daemon/gvfsbackendadmin.c | 46 +++++++++++++++++++++++++++++++++++++++
  14. 1 file changed, 46 insertions(+)
  15. diff --git a/daemon/gvfsbackendadmin.c b/daemon/gvfsbackendadmin.c
  16. index 32b51b1a..9a7e8295 100644
  17. --- a/daemon/gvfsbackendadmin.c
  18. +++ b/daemon/gvfsbackendadmin.c
  19. @@ -807,6 +807,51 @@ do_move (GVfsBackend *backend,
  20. complete_job (job, error);
  21. }
  22. +static void
  23. +do_pull (GVfsBackend *backend,
  24. + GVfsJobPull *pull_job,
  25. + const char *source,
  26. + const char *local_path,
  27. + GFileCopyFlags flags,
  28. + gboolean remove_source,
  29. + GFileProgressCallback progress_callback,
  30. + gpointer progress_callback_data)
  31. +{
  32. + GVfsBackendAdmin *self = G_VFS_BACKEND_ADMIN (backend);
  33. + GVfsJob *job = G_VFS_JOB (pull_job);
  34. + GError *error = NULL;
  35. + GFile *src_file, *dst_file;
  36. +
  37. + /* Pull method is necessary when user/group needs to be restored, return
  38. + * G_IO_ERROR_NOT_SUPPORTED in other cases to proceed with the fallback code.
  39. + */
  40. + if (!(flags & G_FILE_COPY_ALL_METADATA))
  41. + {
  42. + g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR,
  43. + G_IO_ERROR_NOT_SUPPORTED,
  44. + _("Operation not supported"));
  45. + return;
  46. + }
  47. +
  48. + if (!check_permission (self, job))
  49. + return;
  50. +
  51. + src_file = g_file_new_for_path (source);
  52. + dst_file = g_file_new_for_path (local_path);
  53. +
  54. + if (remove_source)
  55. + g_file_move (src_file, dst_file, flags, job->cancellable,
  56. + progress_callback, progress_callback_data, &error);
  57. + else
  58. + g_file_copy (src_file, dst_file, flags, job->cancellable,
  59. + progress_callback, progress_callback_data, &error);
  60. +
  61. + g_object_unref (src_file);
  62. + g_object_unref (dst_file);
  63. +
  64. + complete_job (job, error);
  65. +}
  66. +
  67. static void
  68. do_query_settable_attributes (GVfsBackend *backend,
  69. GVfsJobQueryAttributes *query_job,
  70. @@ -927,6 +972,7 @@ g_vfs_backend_admin_class_init (GVfsBackendAdminClass * klass)
  71. backend_class->set_attribute = do_set_attribute;
  72. backend_class->delete = do_delete;
  73. backend_class->move = do_move;
  74. + backend_class->pull = do_pull;
  75. backend_class->query_settable_attributes = do_query_settable_attributes;
  76. backend_class->query_writable_namespaces = do_query_writable_namespaces;
  77. }
  78. --
  79. 2.24.1