Skip to content
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
19 changes: 7 additions & 12 deletions cmd/cnbBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,12 @@ func isBuilder(utils cnbutils.BuildUtils) error {
return nil
}

func isZip(path string) bool {
func verifyZip(path string) error {
r, err := zip.OpenReader(path)

switch {
case err == nil:
if err == nil {
_ = r.Close()
return true
case err == zip.ErrFormat:
return false
default:
return false
}
return err
}

func cleanDir(dir string, utils cnbutils.BuildUtils) error {
Expand All @@ -169,13 +163,14 @@ func cleanDir(dir string, utils cnbutils.BuildUtils) error {
}

func extractZip(source, target string) error {
if !isZip(source) {
err := verifyZip(source)
if err != nil {
log.SetErrorCategory(log.ErrorBuild)
return errors.New("application path must be a directory or zip")
return errors.Wrapf(err, "'%s' is not a valid archive", source)
}

log.Entry().Infof("Extracting archive '%s' to '%s'", source, target)
_, err := piperutils.Unzip(source, target)
_, err = piperutils.Unzip(source, target)
if err != nil {
log.SetErrorCategory(log.ErrorBuild)
return errors.Wrapf(err, "Extracting archive '%s' to '%s' failed", source, target)
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_cnb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestCNBIntegrationNonZipPath(t *testing.T) {
err := container.whenRunningPiperCommand("cnbBuild", "--noTelemetry", "--verbose", "--containerImageName", "not-found", "--containerImageTag", "0.0.1", "--containerRegistryUrl", registryURL, "--path", "mta.yaml")
assert.Error(t, err)

container.assertHasOutput(t, "Copying '/project/mta.yaml' into '/workspace' failed: application path must be a directory or zip")
container.assertHasOutput(t, "Copying '/project/mta.yaml' into '/workspace' failed: '/project/mta.yaml' is not a valid archive: zip: not a valid zip file")
container.terminate(t)
}

Expand Down
Loading