Skip to content

Commit

Permalink
Merge pull request #35 from WillAbides/checksumcellar
Browse files Browse the repository at this point in the history
make update-checksums use a temp dir for the cellar by default
  • Loading branch information
WillAbides authored Nov 26, 2019
2 parents 19bd6df + 55b3d5b commit 2c2e0ae
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cmd/bindown/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ type configUpdateChecksumsCmd struct {
TargetFile string `kong:"required=true,arg,help=${config_checksums_bin_help}"`
}

func (d *configUpdateChecksumsCmd) Run(*kong.Context) error {
func (d *configUpdateChecksumsCmd) Run(kctx *kong.Context) error {
config, err := bindown.LoadConfigFile(cli.Configfile)
if err != nil {
return fmt.Errorf("error loading config from %q", cli.Configfile)
}
tmpDir, err := ioutil.TempDir("", "bindown")
if err != nil {
return err
}
defer func() {
err = os.RemoveAll(tmpDir)
if err != nil {
kctx.Errorf("error deleting temp directory, %q", tmpDir)
}
}()

binary := path.Base(d.TargetFile)
binDir := path.Dir(d.TargetFile)

cellarDir := cli.CellarDir
if cellarDir == "" {
cellarDir = filepath.Join(tmpDir, "cellar")
}

downloaders, ok := config.Downloaders[binary]
if !ok {
return fmt.Errorf("nothing configured for %q", binary)
Expand All @@ -60,7 +76,7 @@ func (d *configUpdateChecksumsCmd) Run(*kong.Context) error {
for _, downloader := range downloaders {
err = downloader.UpdateChecksum(bindown.UpdateChecksumOpts{
DownloaderName: binary,
CellarDir: cli.CellarDir,
CellarDir: cellarDir,
TargetDir: binDir,
})
if err != nil {
Expand Down

0 comments on commit 2c2e0ae

Please sign in to comment.