Skip to content

Commit 2b9b930

Browse files
vinovoCopilot
andauthored
fix: ensure download path exists before downloading for update (#592)
* fix: ensure download path exists before downloading for update * fix: change 0755 to 0700 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5b7c27e commit 2b9b930

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

runner/cmd/nexa-cli/update.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ func download(url, dst string, progress chan int64) error {
174174
defer close(progress)
175175
}
176176

177-
manifestPath := filepath.Join(filepath.Dir(dst), "manifest.json")
177+
// Ensure destination directory exists before accessing manifest or file
178+
dir := filepath.Dir(dst)
179+
if err := os.MkdirAll(dir, 0700); err != nil {
180+
return err
181+
}
182+
manifestPath := filepath.Join(dir, "manifest.json")
178183
manifest, err := os.Open(manifestPath)
179184
if err == nil {
180185
defer manifest.Close()
@@ -189,7 +194,7 @@ func download(url, dst string, progress chan int64) error {
189194
return nil
190195
}
191196

192-
file, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0644)
197+
file, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
193198
if err != nil {
194199
return err
195200
}

0 commit comments

Comments
 (0)