Skip to content

Commit

Permalink
Merge pull request #360 from meier-christoph/patch-1
Browse files Browse the repository at this point in the history
fix: close tmp file before rename
  • Loading branch information
joaopapereira authored Feb 20, 2024
2 parents f7c3651 + 728e3d4 commit 498f554
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/vendir/fetch/http/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ func (t *Sync) Sync(dstPath string, tempArea ctlfetch.TempArea) (ctlconf.LockDir
return lockConf, err
}

defer tmpFile.Close()
defer os.Remove(tmpFile.Name())

err = t.downloadFileAndChecksum(tmpFile)
if err != nil {
tmpFile.Close()
return lockConf, fmt.Errorf("Downloading URL: %s", err)
}

incomingTmpPath := filepath.Dir(tmpFile.Name())
archivePath := filepath.Join(incomingTmpPath, path.Base(t.opts.URL))
tmpFile.Close()
err = os.Rename(tmpFile.Name(), archivePath)
if err != nil {
return lockConf, err
Expand Down

0 comments on commit 498f554

Please sign in to comment.