From db2aa814349bda2da387d7e66a28a5453952a3cb Mon Sep 17 00:00:00 2001 From: Matthew John Date: Mon, 27 May 2024 06:29:58 +0100 Subject: [PATCH] Update Unzip to retain previous signature to avoid breaking external usage Make filesToUnzip a glob of remaining arguments and set default if the argument has not been provided Issue #315 --- lib/files.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/files.go b/lib/files.go index d5148016..96e1100a 100644 --- a/lib/files.go +++ b/lib/files.go @@ -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) @@ -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[]) } 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