From 681ac3eafd027c8d563ba337a5945eb29d0d5b39 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 26 Nov 2019 10:26:14 -0600 Subject: [PATCH] make update-checksums use a temp dir for the cellar by default --- cmd/bindown/config.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 {