Skip to content

Commit

Permalink
make update-checksums use a temp dir for the cellar by default
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Nov 26, 2019
1 parent 4cfc1e8 commit 681ac3e
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 681ac3e

Please sign in to comment.