fixed errors identified by gosec

This commit is contained in:
2026-05-06 19:18:38 -06:00
parent 3f1001f3d4
commit 8a2e6756cc
3 changed files with 17 additions and 6 deletions
+12 -3
View File
@@ -35,7 +35,10 @@ func downloadToDisk(url, destPath string, c http.Client) error {
defer resp.Body.Close()
// make sure the dir structure exists
os.MkdirAll(filepath.Dir(destPath), 0755)
err = os.MkdirAll(filepath.Dir(destPath), 0750)
if err != nil {
return err
}
// use a tmp file for the initial fetch in case it fails
tempPath := destPath + ".tmp"
@@ -47,13 +50,19 @@ func downloadToDisk(url, destPath string, c http.Client) error {
_, err = io.Copy(tmpFile, resp.Body)
if err != nil {
os.Remove(tempPath)
removeErr := os.Remove(tempPath)
if removeErr != nil {
slog.Warn("failed to remove temp file", "path", tempPath, "err", removeErr)
}
return err
}
// mv file to final location
if err := os.Rename(tempPath, destPath); err != nil {
os.Remove(tempPath)
removeErr := os.Remove(tempPath)
if removeErr != nil {
slog.Warn("failed to remove temp file", "path", tempPath, "err", removeErr)
}
return err
}
return nil