Skip to content

Commit 70f04a3

Browse files
committed
support downloading multiple files from one archive
1 parent b17bc12 commit 70f04a3

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

.toolbox.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
tools:
2+
age:
3+
additional:
4+
- age-keygen
5+
github: FiloSottile/age
26
gh:
37
github: cli/cli
48
check: version

pkg/fetcher/fetch.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,20 @@ func (f *fetcher) fetchTool(tool *types.Tool, toolName string, url string, tmpDi
410410
if !extracted {
411411
downloadedName = fileName
412412
}
413+
if err = f.moveToTarget(tool, toolName, targetDir, dir, downloadedName, false); err != nil {
414+
return err
415+
}
416+
417+
for _, add := range tool.Additional {
418+
if toolName != add {
419+
if err = f.moveToTarget(tool, add, targetDir, dir, add, true); err != nil {
420+
return err
421+
}
422+
}
423+
}
424+
425+
return nil
413426

414-
return f.moveToTarget(tool, toolName, targetDir, dir, downloadedName)
415427
}
416428

417429
func (f *fetcher) validate(targetPath string, check string) error {
@@ -446,6 +458,7 @@ func (f *fetcher) moveToTarget(
446458
targetDir string,
447459
dir string,
448460
downloadedName string,
461+
isAdditional bool,
449462
) error {
450463
targetFilePath, err := filepath.Abs(filepath.Join(targetDir, trueToolName))
451464
if err != nil {
@@ -463,7 +476,7 @@ func (f *fetcher) moveToTarget(
463476
if err != nil {
464477
return err
465478
}
466-
if !ok {
479+
if !ok && !isAdditional {
467480
return fmt.Errorf("could not find: %s", downloadedName)
468481
}
469482
return nil
@@ -484,28 +497,29 @@ func (f *fetcher) copyTool(
484497
for _, file := range files {
485498
if file.IsDir() {
486499
dirs = append(dirs, file)
487-
}
488-
if fileMatches(file, fileName) {
500+
} else {
501+
if fileMatches(file, fileName) {
489502

490-
sourcePath := filepath.Join(dir, file.Name())
491-
targetPath := filepath.Join(targetDir, binaryName(targetName))
503+
sourcePath := filepath.Join(dir, file.Name())
504+
targetPath := filepath.Join(targetDir, binaryName(targetName))
492505

493-
if err := copyFile(sourcePath, targetPath); err != nil {
494-
return false, err
495-
}
496-
if err := f.validate(targetPath, tool.Check); err != nil {
497-
return true, err
498-
}
506+
if err := copyFile(sourcePath, targetPath); err != nil {
507+
return false, err
508+
}
509+
if err := f.validate(targetPath, tool.Check); err != nil {
510+
return true, err
511+
}
499512

500-
if f.upx {
501-
if tool.SkipUpx {
502-
log.Printf("⏭️️ Skipping upx compression")
503-
} else {
504-
f.upxCompress(targetPath)
513+
if f.upx {
514+
if tool.SkipUpx {
515+
log.Printf("⏭️️ Skipping upx compression")
516+
} else {
517+
f.upxCompress(targetPath)
518+
}
505519
}
506-
}
507520

508-
return true, nil
521+
return true, nil
522+
}
509523
}
510524
}
511525
for _, d := range dirs {

0 commit comments

Comments
 (0)