Upgraded archiver dependency to v3.5.1 (#2378)

This commit is contained in:
Ankit Chawla
2022-03-14 10:29:28 +05:30
committed by GitHub
parent 21c76683ef
commit 2f8fde0af0
6 changed files with 49 additions and 23 deletions
+3 -4
View File
@@ -26,7 +26,6 @@ import (
"github.com/dchest/uniuri"
"github.com/hashicorp/go-multierror"
"github.com/mholt/archiver"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
@@ -208,7 +207,7 @@ func CreateArchive(client client.Interface, input cli.Input, includeFiles []stri
func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool) (string, error) {
// Unique name for the archive
archiveName := archiveName(archiveNameHint, archiveInput)
archiveFileName := archiveName(archiveNameHint, archiveInput) + ".zip"
// Get files from inputs as number of files decide next steps
files, err := utils.FindAllGlobs(archiveInput...)
@@ -224,7 +223,7 @@ func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool)
}
// if it's an existing zip file OR we're not supposed to zip it, don't do anything
if archiver.Zip.Match(files[0]) || noZip {
if match, _ := utils.IsZip(files[0]); match || noZip {
return files[0], nil
}
}
@@ -235,7 +234,7 @@ func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool)
return "", errors.Wrap(err, "error create temporary archive directory")
}
archivePath, err := utils.MakeZipArchive(filepath.Join(tmpDir, archiveName), archiveInput...)
archivePath, err := utils.MakeZipArchive(filepath.Join(tmpDir, archiveFileName), archiveInput...)
if err != nil {
return "", errors.Wrap(err, "create archive file")
}
+11 -5
View File
@@ -27,7 +27,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/go-git/go-git/v5"
"github.com/mholt/archiver"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -440,6 +440,7 @@ func applyResources(fclient client.Interface, specDir string, fr *FissionResourc
func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv1.Archive, error) {
// get root dir
var rootDir string
if len(aus.RootDir) == 0 {
rootDir = filepath.Clean(specDir + "/..")
} else {
@@ -451,7 +452,9 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
// XXX if there are lots of globs it's probably more efficient
// to do a filepath.Walk and call path.Match on each path...
files := make([]string, 0)
if len(aus.IncludeGlobs) == 1 && archiver.Zip.Match(aus.IncludeGlobs[0]) {
//checking if file is a zip
if match, _ := utils.IsZip(aus.IncludeGlobs[0]); match && len(aus.IncludeGlobs) == 1 {
files = append(files, aus.IncludeGlobs[0])
} else {
for _, relativeGlob := range aus.IncludeGlobs {
@@ -486,13 +489,16 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
}
if len(files) > 1 || !isSingleFile {
// zip up the file list
archiveFile, err := os.CreateTemp("", fmt.Sprintf("fission-archive-%v", aus.Name))
// Generate archive name with .zip extension and pack all files under it.
archiveFile, err := os.CreateTemp("", fmt.Sprintf("fission-archive-%v-*.zip", aus.Name))
if err != nil {
return nil, err
}
archiveFileName = archiveFile.Name()
err = archiver.Zip.Make(archiveFileName, files)
//This instance is required to allow overwriting and not changing DefaultZip
zipOverwrite := archiver.Zip{OverwriteExisting: true}
err = zipOverwrite.Archive(files, archiveFileName)
if err != nil {
return nil, err
}