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)