diff --git a/cmd/bindown/config.go b/cmd/bindown/config.go index 663bffd..72022bb 100644 --- a/cmd/bindown/config.go +++ b/cmd/bindown/config.go @@ -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) @@ -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 {