diff --git a/cmd/artifact/install/install.go b/cmd/artifact/install/install.go index 47538b4dd..b8f49a265 100644 --- a/cmd/artifact/install/install.go +++ b/cmd/artifact/install/install.go @@ -337,7 +337,7 @@ func (o *artifactInstallOptions) RunArtifactInstall(ctx context.Context, args [] return err } // Extract artifact and move it to its destination directory - _, err = utils.ExtractTarGz(f, destDir, result.Type, 0) + _, err = utils.ExtractTarGz(f, destDir, 0) if err != nil { return fmt.Errorf("cannot extract %q to %q: %w", result.Filename, destDir, err) } diff --git a/internal/follower/follower.go b/internal/follower/follower.go index 7d63e6b17..398c6fcfc 100644 --- a/internal/follower/follower.go +++ b/internal/follower/follower.go @@ -291,7 +291,7 @@ func (f *Follower) pull(ctx context.Context) (filePaths []string, res *oci.Regis } // Extract artifact and move it to its destination directory - filePaths, err = utils.ExtractTarGz(file, f.tmpDir, res.Type, 0) + filePaths, err = utils.ExtractTarGz(file, f.tmpDir, 0) if err != nil { return filePaths, res, fmt.Errorf("unable to extract %q to %q: %w", res.Filename, f.tmpDir, err) } diff --git a/internal/utils/extract.go b/internal/utils/extract.go index 5f18f0d07..1f7433a8a 100644 --- a/internal/utils/extract.go +++ b/internal/utils/extract.go @@ -24,13 +24,11 @@ import ( "os" "path/filepath" "strings" - - "github.com/falcosecurity/falcoctl/pkg/oci" ) // ExtractTarGz extracts a *.tar.gz compressed archive and moves its content to destDir. // Returns a slice containing the full path of the extracted files. -func ExtractTarGz(gzipStream io.Reader, destDir string, artifactType oci.ArtifactType, stripPathComponents int) ([]string, error) { +func ExtractTarGz(gzipStream io.Reader, destDir string, stripPathComponents int) ([]string, error) { var files []string uncompressedStream, err := gzip.NewReader(gzipStream) @@ -59,16 +57,11 @@ func ExtractTarGz(gzipStream io.Reader, destDir string, artifactType oci.Artifac switch header.Typeflag { case tar.TypeDir: - if artifactType == oci.Plugin || artifactType == oci.Rulesfile { - return nil, fmt.Errorf("unexepected dir inside the archive, "+ - "expected to find only files without any tree structure for %q artifacts", artifactType.String()) - } else if artifactType == oci.Asset { - d := filepath.Join(destDir, strippedName) - if err = os.Mkdir(filepath.Clean(d), 0o750); err != nil { - return nil, err - } - files = append(files, d) + d := filepath.Join(destDir, strippedName) + if err = os.Mkdir(filepath.Clean(d), 0o750); err != nil { + return nil, err } + files = append(files, d) case tar.TypeReg: f := filepath.Join(destDir, strippedName) outFile, err := os.Create(filepath.Clean(f)) diff --git a/pkg/driver/distro/distro.go b/pkg/driver/distro/distro.go index 2114b2c2f..628b964e3 100644 --- a/pkg/driver/distro/distro.go +++ b/pkg/driver/distro/distro.go @@ -35,7 +35,6 @@ import ( "github.com/falcosecurity/falcoctl/internal/utils" drivertype "github.com/falcosecurity/falcoctl/pkg/driver/type" - "github.com/falcosecurity/falcoctl/pkg/oci" "github.com/falcosecurity/falcoctl/pkg/output" ) @@ -323,7 +322,7 @@ func downloadKernelSrc(ctx context.Context, // todo(loresuso,fededp): use oci.Asset as the artifact type // oci.Asset is generic enough to be used for kernel sources but we might want to find // a better way to handle this. - _, err = utils.ExtractTarGz(resp.Body, fullKernelDir, oci.Asset, stripComponents) + _, err = utils.ExtractTarGz(resp.Body, fullKernelDir, stripComponents) if err != nil { return env, err }