lib/repo: read split xattrs content from file-xattrs-link objects
authorLuca BRUNO <luca.bruno@coreos.com>
Wed, 2 Mar 2022 16:45:01 +0000 (16:45 +0000)
committerLuca BRUNO <luca.bruno@coreos.com>
Wed, 2 Mar 2022 16:45:01 +0000 (16:45 +0000)
src/libostree/ostree-repo.c

index 71a01d59d2fb77a5ce66852d381e938629ce05be..a27591b3bd1481daa999bf0b8bfbf222b901a65e 100644 (file)
@@ -4176,6 +4176,32 @@ repo_load_file_archive (OstreeRepo *self,
     }
 }
 
+static GVariant *
+_ostree_repo_read_xattrs_file_link (OstreeRepo   *self,
+                                    const char   *checksum,
+                                    GCancellable *cancellable,
+                                    GError      **error)
+{
+  g_assert (self != NULL);
+  g_assert (checksum != NULL);
+
+  char xattr_path[_OSTREE_LOOSE_PATH_MAX];
+  _ostree_loose_path (xattr_path, checksum, OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK, self->mode);
+
+  g_autoptr(GVariant) xattrs = NULL;
+  glnx_autofd int fd = -1;
+  if (!glnx_openat_rdonly (self->objects_dir_fd, xattr_path, FALSE, &fd, error))
+    return FALSE;
+
+  g_assert (fd >= 0);
+  if (!ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a(ayay)"), TRUE,
+                           &xattrs, error))
+    return glnx_prefix_error_null (error, "Deserializing xattrs content");
+
+  g_assert (xattrs != NULL);
+  return g_steal_pointer (&xattrs);
+}
+
 gboolean
 _ostree_repo_load_file_bare (OstreeRepo         *self,
                              const char         *checksum,
@@ -4310,6 +4336,15 @@ _ostree_repo_load_file_bare (OstreeRepo         *self,
             return FALSE;
         }
     }
+  else if (self->mode == OSTREE_REPO_MODE_BARE_SPLIT_XATTRS)
+    {
+      if (out_xattrs)
+        {
+          ret_xattrs = _ostree_repo_read_xattrs_file_link(self, checksum, cancellable, error);
+          if (ret_xattrs == NULL)
+            return FALSE;
+        }
+    }
   else
     {
       g_assert_not_reached ();