libarchive: Fix assertion error if used with CANONICAL_PERMISSIONS
authorColin Walters <walters@verbum.org>
Thu, 28 Sep 2017 19:41:02 +0000 (15:41 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 28 Sep 2017 19:59:24 +0000 (19:59 +0000)
I was trying to do a change for rpm-ostree to use
`OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS`
for container builds with `bare-user-only,` but hit an assertion here
ultimtely because we weren't setting `standard::type`.

Rather than hand-rolling `GFileInfo` creation, use the stat buffer conversion
code which is more robust and used in multiple places already.

Closes: #1227
Approved by: jlebon

src/libostree/ostree-repo-libarchive.c

index 414981df9749a64f9358cbd2bc40fe5a7d79b9e3..64d8a503c4ac72d970d62400ba9e6bda0b6fb39e 100644 (file)
@@ -871,10 +871,14 @@ ostree_repo_import_archive_to_mtree (OstreeRepo                   *self,
   if (opts->autocreate_parents &&
       ostree_mutable_tree_get_metadata_checksum (mtree) == NULL)
     {
-      glnx_unref_object GFileInfo *fi = g_file_info_new ();
-      g_file_info_set_attribute_uint32 (fi, "unix::uid", 0);
-      g_file_info_set_attribute_uint32 (fi, "unix::gid", 0);
-      g_file_info_set_attribute_uint32 (fi, "unix::mode", DEFAULT_DIRMODE);
+      /* _ostree_stbuf_to_gfileinfo() only looks at these fields,
+       * but we use it to ensure it sets all of the relevant GFileInfo
+       * properties.
+       */
+      struct stat stbuf = { .st_mode = DEFAULT_DIRMODE,
+                            .st_uid = 0,
+                            .st_gid = 0 };
+      g_autoptr(GFileInfo) fi = _ostree_stbuf_to_gfileinfo (&stbuf);
 
       g_autoptr(GFileInfo) mfi = NULL;
       (void)_ostree_repo_commit_modifier_apply (self, modifier, "/",