From 20cf67d5d47c6431cbe96975a086dd8bf6ee940f Mon Sep 17 00:00:00 2001 From: Megamind <882485+jeff-mccoy@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:32:24 -0500 Subject: [PATCH] Ensure a target directory exists prior to downloading files (#909) ## Description Prevent file download failure when the target directory does not exist Fixes #901 --- src/internal/utils/network.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/internal/utils/network.go b/src/internal/utils/network.go index ba364d90b2..e4c6236595 100644 --- a/src/internal/utils/network.go +++ b/src/internal/utils/network.go @@ -55,6 +55,11 @@ func Fetch(url string) io.ReadCloser { func DownloadToFile(url string, target string, cosignKeyPath string) { + // Always ensure the target directory exists + if err := CreateFilePath(target); err != nil { + message.Fatalf(err, "Unable to create file path: %s", target) + } + // Create the file destinationFile, err := os.Create(target) if err != nil {