[libgsystem/submodule] fileutil: Add API to set xattrs of a filename relative to a dir fd



commit 31cd0b96bba5ccf391f4c4f5d94cddce44c65793
Author: Colin Walters <walters verbum org>
Date:   Wed Feb 26 16:25:59 2014 -0500

    fileutil: Add API to set xattrs of a filename relative to a dir fd
    
    This is a Linux-specific way to work around the missing lsetxattrat().

 gsystem-file-utils.c |   62 ++++++++++++++++++++++++++++++++++---------------
 gsystem-file-utils.h |    6 +++++
 2 files changed, 49 insertions(+), 19 deletions(-)
---
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c
index 0260603..27e0e2d 100644
--- a/gsystem-file-utils.c
+++ b/gsystem-file-utils.c
@@ -1588,30 +1588,16 @@ gs_fd_set_all_xattrs (int            fd,
 #endif
 }
 
-/**
- * gs_file_set_all_xattrs:
- * @file: File descriptor
- * @xattrs: Extended attributes
- * @cancellable: Cancellable
- * @error: Error
- *
- * For each attribute in @xattrs, set its value on the file or
- * directory referred to by @file.  This function does not remove any
- * attributes not in @xattrs.
- */
-gboolean
-gs_file_set_all_xattrs (GFile         *file,
-                        GVariant      *xattrs,
-                        GCancellable  *cancellable,
-                        GError       **error)
+static gboolean
+set_all_xattrs_for_path (const char    *path,
+                         GVariant      *xattrs,
+                         GCancellable  *cancellable,
+                         GError       **error)
 {
 #ifdef GSYSTEM_CONFIG_XATTRS
   gboolean ret = FALSE;
-  const char *path;
   int i, n;
 
-  path = gs_file_get_path_cached (file);
-
   n = g_variant_n_children (xattrs);
   for (i = 0; i < n; i++)
     {
@@ -1642,3 +1628,41 @@ gs_file_set_all_xattrs (GFile         *file,
   return TRUE;
 #endif
 }
+
+gboolean
+gs_dfd_and_name_set_all_xattrs (int            dfd,
+                                const char    *name,
+                                GVariant      *xattrs,
+                                GCancellable  *cancellable,
+                                GError       **error)
+{
+  /* A workaround for the lack of lsetxattrat(), thanks to Florian Weimer:
+   * https://mail.gnome.org/archives/ostree-list/2014-February/msg00017.html
+   */
+  char *path = g_strdup_printf ("/proc/self/fd/%d/%s", dfd, name);
+  gboolean ret;
+
+  ret = set_all_xattrs_for_path (path, xattrs, cancellable, error);
+  g_free (path);
+  return ret;
+}
+
+/**
+ * gs_file_set_all_xattrs:
+ * @file: File descriptor
+ * @xattrs: Extended attributes
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * For each attribute in @xattrs, set its value on the file or
+ * directory referred to by @file.  This function does not remove any
+ * attributes not in @xattrs.
+ */
+gboolean
+gs_file_set_all_xattrs (GFile         *file,
+                        GVariant      *xattrs,
+                        GCancellable  *cancellable,
+                        GError       **error)
+{
+  return set_all_xattrs_for_path (gs_file_get_path_cached (file), xattrs, cancellable, error);
+}
diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h
index 021aebb..d1cfda2 100644
--- a/gsystem-file-utils.h
+++ b/gsystem-file-utils.h
@@ -162,6 +162,12 @@ gboolean gs_fd_set_all_xattrs (int            fd,
                                GCancellable  *cancellable,
                                GError       **error);
 
+gboolean gs_dfd_and_name_set_all_xattrs (int            dfd,
+                                         const char    *name,
+                                         GVariant      *xattrs,
+                                         GCancellable  *cancellable,
+                                         GError       **error);
+
 gboolean gs_file_set_all_xattrs (GFile         *file,
                                  GVariant      *xattrs,
                                  GCancellable  *cancellable,


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