Use mholt/archives instead of mholt/archiver (#3128)

* Use mholt/archives instead of mholt/archiver
* Fix validations
* Fix iszip function
* Fix directory
* Add better path sanitization
* ensure safe dir is passed
* Fix file permissions
* Fix config path
* Sanitize builder source path

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2025-01-08 11:00:54 +05:30
committed by GitHub
parent 54b67b5171
commit 4bce904c96
12 changed files with 721 additions and 155 deletions
+4 -7
View File
@@ -27,7 +27,6 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/go-git/go-git/v5"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -358,7 +357,7 @@ func applyArchives(input cli.Input, fclient cmd.Client, specDir string, fr *Fiss
// create archives locally and calculate checksums
for _, aus := range fr.ArchiveUploadSpecs {
ar, err := localArchiveFromSpec(specDir, &aus)
ar, err := localArchiveFromSpec(input.Context(), specDir, &aus)
if err != nil {
return err
}
@@ -501,7 +500,7 @@ func applyResources(input cli.Input, fclient cmd.Client, specDir string, fr *Fis
// localArchiveFromSpec creates an archive on the local filesystem from the given spec,
// and returns its path and checksum.
func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv1.Archive, error) {
func localArchiveFromSpec(ctx context.Context, specDir string, aus *spectypes.ArchiveUploadSpec) (*fv1.Archive, error) {
// get root dir
var rootDir string
@@ -518,7 +517,7 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
files := make([]string, 0)
// checking if file is a zip
if match, _ := utils.IsZip(aus.IncludeGlobs[0]); match && len(aus.IncludeGlobs) == 1 {
if match, _ := utils.IsZip(ctx, aus.IncludeGlobs[0]); match && len(aus.IncludeGlobs) == 1 {
files = append(files, aus.IncludeGlobs[0])
} else {
for _, relativeGlob := range aus.IncludeGlobs {
@@ -560,9 +559,7 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
}
archiveFileName = archiveFile.Name()
// This instance is required to allow overwriting and not changing DefaultZip
zipOverwrite := archiver.Zip{OverwriteExisting: true}
err = zipOverwrite.Archive(files, archiveFileName)
_, err = utils.MakeZipArchiveWithGlobs(ctx, archiveFileName, files...)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -176,7 +176,7 @@ func (opts *DestroySubCommand) insertNSToResource(input cli.Input, fr *FissionRe
return result.ErrorOrNil()
}
func deleteResources(ctx context.Context, fclient cmd.Client, fr *FissionResources, forceDelete bool) error {
func deleteResources(ctx context.Context, fclient cmd.Client, fr *FissionResources, _ bool) error {
var err error