1
0
mirror of https://github.com/projectatomic/atomic.git synced 2026-02-05 18:45:01 +01:00

pull: import correctly images with xattrs

libarchive[1] does not handle xattrs found in the PAX extended header.
In such cases, fallback to extract the tarball and after import it
into OSTree.

[1] https://github.com/libarchive/libarchive/pull/691

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #665
Approved by: rhatdan
This commit is contained in:
Giuseppe Scrivano
2016-09-26 12:21:45 +02:00
committed by Atomic Bot
parent fc0aea92ea
commit 71947f23f7

View File

@@ -866,9 +866,33 @@ class SystemContainers(object):
return OSTree.RepoCommitFilterResult.ALLOW
modifier = OSTree.RepoCommitModifier.new(0, filter_func, None)
repo.write_archive_to_mtree(Gio.File.new_for_path(tar), mtree, modifier, True)
root = repo.write_mtree(mtree)[1]
metav = GLib.Variant("a{sv}", {'docker.layer': GLib.Variant('s', layer)})
imported = False
try:
repo.write_archive_to_mtree(Gio.File.new_for_path(tar), mtree, modifier, True)
root = repo.write_mtree(mtree)[1]
csum = repo.write_commit(None, "", None, metav, root)[1]
imported = True
except GLib.GError as e: #pylint: disable=catching-non-exception
# libarchive which is used internally by OSTree to import a tarball doesn't support correctly
# files with xattrs. If that happens, extract the tarball and import the directory.
if e.domain != "g-io-error-quark": # pylint: disable=no-member
raise e #pylint: disable=raising-non-exception
if not imported:
try:
temp_dir = tempfile.mkdtemp()
with tarfile.open(tar, 'r') as t:
t.extractall(temp_dir)
repo.write_directory_to_mtree(Gio.File.new_for_path(temp_dir), mtree, modifier)
root = repo.write_mtree(mtree)[1]
csum = repo.write_commit(None, "", None, metav, root)[1]
finally:
shutil.rmtree(temp_dir)
root = repo.write_mtree(mtree)[1]
csum = repo.write_commit(None, "", None, metav, root)[1]
repo.transaction_set_ref(None, "%s%s" % (OSTREE_OCIIMAGE_PREFIX, layer), csum)