Skip to content

Commit 9d772e6

Browse files
authored
Ensure cache directory exists (#205)
1 parent 2bbfaf5 commit 9d772e6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/leeway/cache/local/fs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (fsc *FilesystemCache) Location(pkg cache.Package) (path string, exists boo
4141
tarPath := filepath.Join(fsc.Origin, fmt.Sprintf("%s.tar", version))
4242
exists = fileExists(tarPath)
4343

44+
// Ensure parent directory exists for download operations
45+
// This is safe to do even if we're just checking existence
46+
_ = os.MkdirAll(filepath.Dir(tarPath), 0755)
47+
4448
return tarPath, exists
4549
}
4650

pkg/leeway/cache/remote/s3.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ func (s *S3Storage) GetObject(ctx context.Context, key string, dest string) (int
303303
d.PartSize = defaultS3PartSize
304304
})
305305

306+
// Ensure parent directory exists
307+
if err := os.MkdirAll(filepath.Dir(dest), 0755); err != nil {
308+
return 0, fmt.Errorf("failed to create parent directory: %w", err)
309+
}
310+
306311
file, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY, 0644)
307312
if err != nil {
308313
return 0, fmt.Errorf("failed to create destination file: %w", err)

0 commit comments

Comments
 (0)