Skip to content

Commit

Permalink
Merge pull request #5 from project-stacker/main
Browse files Browse the repository at this point in the history
add tarwriter fixes from upstream
  • Loading branch information
hallyn authored Feb 23, 2024
2 parents cb3aca5 + bef7765 commit 555a0af
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
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

0 comments on commit 555a0af

Please sign in to comment.