Skip to content

Commit

Permalink
fix: fix cp command to support command aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Nov 2, 2024
1 parent 8bd9ff7 commit 632c0da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/cp/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *Controller) installAndCopy(ctx context.Context, logE *logrus.Entry, par
}
}

if err := c.copy(logE, param, findResult, exeName); err != nil {
if err := c.copy(logE, param, findResult.ExePath, exeName); err != nil {
return err
}
return nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/cp/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"path/filepath"

"github.com/aquaproj/aqua/v2/pkg/config"
"github.com/aquaproj/aqua/v2/pkg/controller/which"
"github.com/sirupsen/logrus"
)

func (c *Controller) copy(logE *logrus.Entry, param *config.Param, findResult *which.FindResult, exeName string) error {
func (c *Controller) copy(logE *logrus.Entry, param *config.Param, exePath string, exeName string) error {
p := filepath.Join(param.Dest, exeName)
if c.runtime.GOOS == "windows" && filepath.Ext(exeName) == "" {
p += ".exe"
Expand All @@ -18,7 +17,7 @@ func (c *Controller) copy(logE *logrus.Entry, param *config.Param, findResult *w
"exe_name": exeName,
"dest": p,
}).Info("coping a file")
if err := c.packageInstaller.Copy(p, findResult.ExePath); err != nil {
if err := c.packageInstaller.Copy(p, exePath); err != nil {
return fmt.Errorf("copy a file: %w", err)
}
return nil
Expand Down
16 changes: 13 additions & 3 deletions pkg/installpackage/check_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,20 @@ func (is *Installer) checkAndCopyFile(ctx context.Context, logE *logrus.Entry, p
return nil
}
logE.Info("copying an executable file")
if err := is.Copy(filepath.Join(is.copyDir, file.Name), exePath); err != nil {
return err
exeNames := map[string]struct{}{}
for _, alias := range pkg.Package.CommandAliases {
if alias.Command == file.Name {
exeNames[alias.Alias] = struct{}{}
}
}
if len(exeNames) == 0 {
exeNames[file.Name] = struct{}{}
}
for exeName := range exeNames {
if err := is.Copy(filepath.Join(is.copyDir, exeName), exePath); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit 632c0da

Please sign in to comment.