Skip to content

Commit

Permalink
support downloading multiple files from one archive
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Jan 31, 2025
1 parent b17bc12 commit 70f04a3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .toolbox.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
tools:
age:
additional:
- age-keygen
github: FiloSottile/age
gh:
github: cli/cli
check: version
Expand Down
52 changes: 33 additions & 19 deletions pkg/fetcher/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,20 @@ func (f *fetcher) fetchTool(tool *types.Tool, toolName string, url string, tmpDi
if !extracted {
downloadedName = fileName
}
if err = f.moveToTarget(tool, toolName, targetDir, dir, downloadedName, false); err != nil {
return err
}

for _, add := range tool.Additional {
if toolName != add {
if err = f.moveToTarget(tool, add, targetDir, dir, add, true); err != nil {
return err
}
}
}

return nil

Check failure on line 426 in pkg/fetcher/fetch.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofumpt)
return f.moveToTarget(tool, toolName, targetDir, dir, downloadedName)
}

func (f *fetcher) validate(targetPath string, check string) error {
Expand Down Expand Up @@ -446,6 +458,7 @@ func (f *fetcher) moveToTarget(
targetDir string,
dir string,
downloadedName string,
isAdditional bool,
) error {
targetFilePath, err := filepath.Abs(filepath.Join(targetDir, trueToolName))
if err != nil {
Expand All @@ -463,7 +476,7 @@ func (f *fetcher) moveToTarget(
if err != nil {
return err
}
if !ok {
if !ok && !isAdditional {
return fmt.Errorf("could not find: %s", downloadedName)
}
return nil
Expand All @@ -484,28 +497,29 @@ func (f *fetcher) copyTool(
for _, file := range files {
if file.IsDir() {
dirs = append(dirs, file)
}
if fileMatches(file, fileName) {
} else {
if fileMatches(file, fileName) {

sourcePath := filepath.Join(dir, file.Name())
targetPath := filepath.Join(targetDir, binaryName(targetName))
sourcePath := filepath.Join(dir, file.Name())
targetPath := filepath.Join(targetDir, binaryName(targetName))

if err := copyFile(sourcePath, targetPath); err != nil {
return false, err
}
if err := f.validate(targetPath, tool.Check); err != nil {
return true, err
}
if err := copyFile(sourcePath, targetPath); err != nil {
return false, err
}
if err := f.validate(targetPath, tool.Check); err != nil {
return true, err
}

if f.upx {
if tool.SkipUpx {
log.Printf("⏭️️ Skipping upx compression")
} else {
f.upxCompress(targetPath)
if f.upx {
if tool.SkipUpx {
log.Printf("⏭️️ Skipping upx compression")
} else {
f.upxCompress(targetPath)
}
}
}

return true, nil
return true, nil
}
}
}
for _, d := range dirs {
Expand Down

0 comments on commit 70f04a3

Please sign in to comment.