Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tarwriter fixes from upstream #5

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions oci/layer/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func GenerateLayer(path string, deltas []mtree.InodeDelta, opt *RepackOptions) (
go func() (Err error) {
// Close with the returned error.
defer func() {
log.Warnf("could not generate layer: %v", Err)
if Err != nil {
log.Warnf("could not generate layer: %v", Err)
}
// #nosec G104
_ = writer.CloseWithError(errors.Wrap(Err, "generate layer"))
}()
Expand Down Expand Up @@ -135,13 +137,21 @@ func GenerateInsertLayer(root string, target string, opaque bool, opt *RepackOpt

go func() (Err error) {
defer func() {
log.Warnf("could not generate insert layer: %v", Err)
if Err != nil {
log.Warnf("could not generate insert layer: %v", Err)
}
// #nosec G104
_ = writer.CloseWithError(errors.Wrap(Err, "generate insert layer"))
}()

tg := newTarGenerator(writer, packOptions.MapOptions)

defer func() {
if err := tg.tw.Close(); err != nil {
log.Warnf("generate insert layer: could not close tar.Writer: %s", err)
}
}()

if opaque {
if err := tg.AddOpaqueWhiteout(target); err != nil {
return err
Expand Down
16 changes: 15 additions & 1 deletion test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ function requires() {
}

function image-verify() {
oci-image-tool validate --type "imageLayout" "$@"
local ocidir="$@"
# test that each generated targz file is valid according to gnutar:
for f in $(ls $ocidir/blobs/sha256/); do
file $ocidir/blobs/sha256/$f | grep "gzip" || {
continue
}
zcat $ocidir/blobs/sha256/$f | tar tvf - >/dev/null || {
rc=$?
file $ocidir/blobs/sha256/$f
echo "error untarring $f: $rc"
return $rc
}
echo $f: valid tar archive
done
oci-image-tool validate --type "imageLayout" "$ocidir"
return $?
}

Expand Down
5 changes: 5 additions & 0 deletions test/insert.bats
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function teardown() {
touch "${INSERTDIR}/test/a"
touch "${INSERTDIR}/test/b"
chmod +x "${INSERTDIR}/test/b"
echo "foo" > "${INSERTDIR}/test/smallfile"

# Make sure rootless mode works.
mkdir -p "${INSERTDIR}/some/path"
Expand All @@ -68,6 +69,10 @@ function teardown() {
[ "$status" -eq 0 ]
image-verify "${IMAGE}"

umoci insert --image "${IMAGE}:${TAG}" "${INSERTDIR}/test/smallfile" /tester/smallfile
[ "$status" -eq 0 ]
image-verify "${IMAGE}"

# Unpack after the inserts.
new_bundle_rootfs
umoci unpack --image "${IMAGE}:${TAG}-new" "$BUNDLE"
Expand Down