Skip to content

Commit

Permalink
Merge pull request #49 from b4b4r07/babarot/fix-45
Browse files Browse the repository at this point in the history
Support gz case (decompress)
  • Loading branch information
b4b4r07 authored May 29, 2022
2 parents 3cbc7cd + 5571304 commit ee71481
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
7 changes: 5 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}:
Expand Down
25 changes: 21 additions & 4 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strings"

"github.com/b4b4r07/afx/pkg/errors"
"github.com/b4b4r07/afx/pkg/logging"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee71481

Please sign in to comment.