Skip to content

Commit

Permalink
Close chunked manifest.json file when reading from tarball
Browse files Browse the repository at this point in the history
Authored-by: Dennis Leon <leonde@vmware.com>
  • Loading branch information
DennisDenuto committed Oct 8, 2021
1 parent 24bda4a commit ff19983
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/imgpkg/cmd/copy_repo_src_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ bundle:
subject.BundleFlags.Bundle = fakeRegistry.ReferenceOnTestServer(
bundleWithNested.BundleName + "@" + bundleWithNested.Digest)

tarDir := assets.CreateTempFolder("tar-copy")
imageTarPath := filepath.Join(tarDir, "bundle.tar")
bundleTarPath := filepath.Join(os.TempDir(), "bundle.tar")
defer os.Remove(bundleTarPath)

err = subject.CopyToTar(imageTarPath)
err = subject.CopyToTar(bundleTarPath)
require.NoError(t, err)

assertTarballContainsOnlyDistributableLayers(imageTarPath, t)
assertTarballContainsOnlyDistributableLayers(bundleTarPath, t)

assertTarballLabelsOuterBundle(imageTarPath, subject.BundleFlags.Bundle, t)
assertTarballLabelsOuterBundle(bundleTarPath, subject.BundleFlags.Bundle, t)
})
}

Expand Down Expand Up @@ -203,8 +203,8 @@ images:
subject.BundleFlags.Bundle = fakeRegistry.ReferenceOnTestServer(bundleWithNested.BundleName + "@" +
bundleWithNested.Digest)

tarDir := assets.CreateTempFolder("tar-copy")
imageTarPath := filepath.Join(tarDir, "bundle.tar")
imageTarPath := filepath.Join(os.TempDir(), "bundle.tar")
defer os.Remove(imageTarPath)

err := subject.CopyToTar(imageTarPath)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/imgpkg/imagetar/tar_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (r TarReader) getIdsFromManifest(file tarFile) (*imagedesc.ImageRefDescript
if err != nil {
return nil, err
}
defer manifestFile.Close()

manifestBytes, err := ioutil.ReadAll(manifestFile)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/imgpkg/imagetar/tar_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (w *TarWriter) Write() error {
if err != nil {
return err
}

defer w.dst.Close()

w.tf = tar.NewWriter(w.dst)
Expand Down
6 changes: 1 addition & 5 deletions test/helpers/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -96,10 +95,7 @@ func (a *Assets) CleanCreatedFolders() {
for _, folder := range a.CreatedFolders {
err := os.RemoveAll(folder)

//TODO: figure out why windows still has a file handle on the bundle.tar file
if runtime.GOOS != "windows" {
require.NoErrorf(a.T, err, "cleaning folder: '%s'", folder)
}
require.NoErrorf(a.T, err, "cleaning folder: '%s'", folder)
}
}

Expand Down

0 comments on commit ff19983

Please sign in to comment.