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
+6 -5
View File
@@ -28,7 +28,7 @@ import (
"strconv"
"time"
"github.com/mholt/archiver"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"go.opencensus.io/plugin/ochttp"
@@ -352,7 +352,8 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req Functio
}
}
if archiver.Zip.Match(tmpPath) && !req.KeepArchive {
//checking if file is a zip
if match, _ := utils.IsZip(tmpPath); match && !req.KeepArchive {
// unarchive tmp file to a tmp unarchive path
id, err := uuid.NewV4()
if err != nil {
@@ -621,14 +622,14 @@ func (fetcher *Fetcher) archive(src string, dst string) error {
} else {
files = append(files, src)
}
return archiver.Zip.Make(dst, files)
return archiver.DefaultZip.Archive(files, dst)
}
// unarchive is a function that unzips a zip file to destination
func (fetcher *Fetcher) unarchive(src string, dst string) error {
err := archiver.Zip.Open(src, dst)
err := archiver.DefaultZip.Unarchive(src, dst)
if err != nil {
return errors.Wrap(err, "failed to unzip file")
return fmt.Errorf("failed to unzip file: %w", err)
}
return nil
}
+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
}
+11 -2
View File
@@ -28,7 +28,7 @@ import (
"path/filepath"
"strings"
"github.com/mholt/archiver"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"golang.org/x/net/context/ctxhttp"
@@ -94,7 +94,7 @@ func MakeZipArchive(targetName string, globs ...string) (string, error) {
}
// zip up the file list
err = archiver.Zip.Make(targetName, files)
err = archiver.DefaultZip.Archive(files, targetName)
if err != nil {
return "", err
}
@@ -205,3 +205,12 @@ func DownloadUrl(ctx context.Context, httpClient *http.Client, url string, local
return nil
}
func IsZip(filename string) (bool, error) {
f, err := os.Open(filename)
if err != nil {
return false, nil
}
defer f.Close()
return archiver.DefaultZip.Match(f)
}