[gvfs/nfs] Set CAN_DELETE, CAN_RENAME and CAN_TRASH for enumerate



commit e8135254a9d837ce3385404c4a812aa54d8d873c
Author: Ross Lagerwall <rosslagerwall gmail com>
Date:   Wed Feb 4 21:54:26 2015 +0000

    Set CAN_DELETE, CAN_RENAME and CAN_TRASH for enumerate

 daemon/gvfsbackendnfs.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/daemon/gvfsbackendnfs.c b/daemon/gvfsbackendnfs.c
index 8d1d9cc..0782fb6 100644
--- a/daemon/gvfsbackendnfs.c
+++ b/daemon/gvfsbackendnfs.c
@@ -1621,6 +1621,7 @@ typedef struct
   GSList *symlink_list;
   GSList *access_list;
   gboolean requires_access;
+  int access_parent;
   GVfsJobEnumerate *op_job;
 } EnumerateHandle;
 
@@ -1679,6 +1680,16 @@ enumerate_stat_cb (int err,
         g_file_info_set_symlink_target (new_info,
                                         g_file_info_get_symlink_target (info));
 
+      if ((g_file_attribute_matcher_matches (handle->op_job->attribute_matcher,
+                                            G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE) ||
+          g_file_attribute_matcher_matches (handle->op_job->attribute_matcher,
+                                            G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME)) &&
+          handle->access_parent >= 0)
+        {
+          g_file_info_set_attribute_boolean (new_info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, 
handle->access_parent & W_OK);
+          g_file_info_set_attribute_boolean (new_info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME, 
handle->access_parent & W_OK);
+        }
+
       g_object_unref (info);
       info = new_info;
     }
@@ -1809,6 +1820,7 @@ enumerate_cb (int err, struct nfs_context *ctx, void *data, void *private_data)
           g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE, d->blksize);
           g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_BLOCKS, d->blocks);
           g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_ALLOCATED_SIZE, d->used);
+          g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE);
 
           etag = create_etag (d->mtime.tv_sec, d->mtime_nsec);
           g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ETAG_VALUE, etag);
@@ -1849,6 +1861,16 @@ enumerate_cb (int err, struct nfs_context *ctx, void *data, void *private_data)
           g_file_info_set_file_type (info, type);
           set_name_info (info, mimetype, d->name, op_job->attribute_matcher);
 
+          if ((g_file_attribute_matcher_matches (op_job->attribute_matcher,
+                                                G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE) ||
+              g_file_attribute_matcher_matches (op_job->attribute_matcher,
+                                                G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME)) &&
+              handle->access_parent >= 0)
+            {
+              g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, 
handle->access_parent & W_OK);
+              g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME, 
handle->access_parent & W_OK);
+            }
+
           if (d->type == NF3LNK &&
               g_file_attribute_matcher_matches (op_job->attribute_matcher,
                                                 G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET))
@@ -1887,6 +1909,19 @@ enumerate_cb (int err, struct nfs_context *ctx, void *data, void *private_data)
     }
 }
 
+static void
+enumerate_access_parent_cb (int err,
+                            struct nfs_context *ctx,
+                            void *data, void *private_data)
+{
+  EnumerateHandle *handle = private_data;
+  GVfsJobEnumerate *op_job = handle->op_job;
+
+  handle->access_parent = err;
+
+  nfs_opendir_async (ctx, op_job->filename, enumerate_cb, handle);
+}
+
 static gboolean
 try_enumerate (GVfsBackend *backend,
                GVfsJobEnumerate *job,
@@ -1899,7 +1934,23 @@ try_enumerate (GVfsBackend *backend,
 
   handle = g_slice_new0 (EnumerateHandle);
   handle->op_job = job;
-  nfs_opendir_async (op_backend->ctx, filename, enumerate_cb, handle);
+  handle->access_parent = -1;
+
+  if (g_file_attribute_matcher_matches (attribute_matcher,
+                                        G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE) ||
+      g_file_attribute_matcher_matches (attribute_matcher,
+                                        G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME))
+    {
+      char *dirname = g_path_get_dirname (filename);
+      nfs_access2_async (op_backend->ctx,
+                         dirname,
+                         enumerate_access_parent_cb, handle);
+      g_free (dirname);
+    }
+  else
+    {
+      nfs_opendir_async (op_backend->ctx, filename, enumerate_cb, handle);
+    }
 
   return TRUE;
 }


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