Skip to content

Commit

Permalink
Update Unzip to retain previous signature to avoid breaking external …
Browse files Browse the repository at this point in the history
…usage

Make filesToUnzip a glob of remaining arguments and set default if the argument has not been provided

Issue #315
  • Loading branch information
MatthewJohn committed May 27, 2024
1 parent 1aa25aa commit db2aa81
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ func CheckFileExist(file string) bool {

// Unzip will decompress a zip archive, moving all files and folders
// within the zip file (parameter 1) to an output directory (parameter 2).
func Unzip(src string, dest string, fileToUnzip string) ([]string, error) {
// fileToUnzip (parameter 3) specifices the file within the zipfile to be extracted.
// This is optional and default to "terraform"
func Unzip(src string, dest string, fileToUnzipSlice ...string) ([]string, error) {
logger.Debugf("Unzipping file %q", src)

// Handle old signature of method, where fileToUnzip did not exist
fileToUnzip := "terraform"
if len(fileToUnzipSlice) > 0 {
fileToUnzip = fileToUnzipSlice[0]
}

var filenames []string

reader, err := zip.OpenReader(src)
Expand Down Expand Up @@ -79,9 +87,9 @@ func Unzip(src string, dest string, fileToUnzip string) ([]string, error) {
unzipWaitGroup.Wait()

if len(filenames) < 1 {
logger.Fatalf("Could not find terraform file in release archive to unzip")
logger.Fatalf("Could not find %s file in release archive to unzip", fileToUnzipSlice[])

Check failure on line 90 in lib/files.go

View workflow job for this annotation

GitHub Actions / fmt_and_vet

syntax error: unexpected ], expected operand

Check failure on line 90 in lib/files.go

View workflow job for this annotation

GitHub Actions / fmt_and_vet

syntax error: unexpected ], expected operand

Check failure on line 90 in lib/files.go

View workflow job for this annotation

GitHub Actions / integration_tests_windows (windows-latest, 1.22)

syntax error: unexpected ], expected operand

Check failure on line 90 in lib/files.go

View workflow job for this annotation

GitHub Actions / integration_tests_linux (ubuntu-latest, 1.22)

syntax error: unexpected ], expected operand
} else if len(filenames) > 1 {
logger.Fatalf("Extracted more files than expected in release archive")
logger.Fatal("Extracted more files than expected in release archive")
}

return filenames, nil
Expand Down

0 comments on commit db2aa81

Please sign in to comment.