From 5571304a59c59e5632d69abe5972ff9200f7c635 Mon Sep 17 00:00:00 2001 From: b4b4r07 Date: Sun, 29 May 2022 14:26:57 +0900 Subject: [PATCH] Support gz case (decompress) --- cmd/install.go | 7 +++++-- pkg/github/github.go | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index e0d8939..72ddfd4 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -10,6 +10,7 @@ import ( "github.com/b4b4r07/afx/pkg/config" "github.com/b4b4r07/afx/pkg/errors" "github.com/b4b4r07/afx/pkg/helpers/templates" + "github.com/b4b4r07/afx/pkg/logging" "github.com/b4b4r07/afx/pkg/state" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" @@ -119,8 +120,10 @@ func (c *installCmd) run(pkgs []config.Package) error { case nil: c.state.Add(pkg) default: - log.Printf("[DEBUG] uninstall %q because installation failed", pkg.GetName()) - pkg.Uninstall(ctx) + if !logging.IsSet() { + log.Printf("[DEBUG] uninstall %q because installation failed", pkg.GetName()) + pkg.Uninstall(ctx) + } } select { case results <- installResult{Package: pkg, Error: err}: diff --git a/pkg/github/github.go b/pkg/github/github.go index 8337180..dd4c9ef 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -11,6 +11,7 @@ import ( "path/filepath" "regexp" "runtime" + "strings" "github.com/b4b4r07/afx/pkg/errors" "github.com/b4b4r07/afx/pkg/logging" @@ -327,14 +328,30 @@ func (r *Release) Unarchive(asset Asset) error { *archiver.Xz: // nothing to customise } + log.Printf("[DEBUG] uaIface: %#v (%T)", uaIface, uaIface) + + var done bool u, ok := uaIface.(archiver.Unarchiver) - if !ok { - return errors.New("cannot type assertion with archiver.Unarchiver") + if ok { + if err := u.Unarchive(archive, r.workdir); err != nil { + return errors.Wrapf(err, "%s: failed to unarchive", r.Name) + } + done = true + } + + d, ok := uaIface.(archiver.Decompressor) + if ok { + fc := archiver.FileCompressor{Decompressor: d} + name := strings.TrimSuffix(asset.Name, filepath.Ext(asset.Name)) + if err := fc.DecompressFile(archive, filepath.Join(r.workdir, name)); err != nil { + return errors.Wrapf(err, "%s: failed to decompress", r.Name) + } + done = true } - if err := u.Unarchive(archive, r.workdir); err != nil { - return errors.Wrapf(err, "%s: failed to unarchive", r.Name) + if !done { + return errors.New("archiver cannot unarchive/decompress file") } log.Printf("[DEBUG] removed archive file: %s", archive)