From 31fd368bda3c870c2d4f77f7b01a56de560534fb Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Sun, 21 Jun 2026 22:31:49 -0700 Subject: [PATCH] fix: create parent dirs for downloads with subdirectory paths Some archive.org file names include directory prefixes (e.g. "ZERO-G - Deepest India/vocal.iso"). MkdirAll only created the output root, not intermediate directories. Added filepath.Dir(MkdirAll) in both downloadFile (CLI) and handleAPIDownload (web). --- main.go | 2 ++ serve.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/main.go b/main.go index e3cb6a0..d69a956 100644 --- a/main.go +++ b/main.go @@ -330,6 +330,8 @@ func cmdDownload(args []string) { } func downloadFile(job downloadJob) (int64, error) { + os.MkdirAll(filepath.Dir(job.OutPath), 0755) + // Check if file already exists and has the expected size if fi, err := os.Stat(job.OutPath); err == nil { if job.Size > 0 && fi.Size() == job.Size { diff --git a/serve.go b/serve.go index 1133939..0430acc 100644 --- a/serve.go +++ b/serve.go @@ -189,6 +189,8 @@ func handleAPIDownload(w http.ResponseWriter, r *http.Request) { jobIDs = append(jobIDs, jobID) go func(j downloadJob, s *downloadState) { + os.MkdirAll(filepath.Dir(j.OutPath), 0755) + client := &http.Client{Timeout: 0} req, _ := http.NewRequest("GET", j.URL, nil) req.Header.Set("User-Agent", userAgent)