added explict mkdir

This commit is contained in:
Shreyas Goenka 2023-06-30 02:25:16 +02:00
parent 5eddeb42eb
commit f111e693b5
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 12 additions and 2 deletions

View File

@ -76,7 +76,7 @@ func download(ctx context.Context, url string, dest string) error {
return fmt.Errorf("failed to download ZIP archive: %s. %s", url, resp.Status) return fmt.Errorf("failed to download ZIP archive: %s. %s", url, resp.Status)
} }
f, err := os.OpenFile(dest, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) f, err := os.Create(dest)
if err != nil { if err != nil {
return err return err
} }
@ -108,13 +108,17 @@ func clonePrivate(ctx context.Context, opts CloneOptions) error {
} }
func clonePublic(ctx context.Context, opts CloneOptions) error { func clonePublic(ctx context.Context, opts CloneOptions) error {
zipDst := filepath.Join(opts.TargetDir, opts.RepositoryName+".zip") tmpDir := os.TempDir()
defer os.Remove(tmpDir)
zipDst := filepath.Join(tmpDir, opts.RepositoryName+".zip")
// Download public repository from github as a ZIP file // Download public repository from github as a ZIP file
err := download(ctx, opts.zipUrl(), zipDst) err := download(ctx, opts.zipUrl(), zipDst)
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(zipDst)
// Decompress the ZIP file // Decompress the ZIP file
err = zip.Extract(zipDst, opts.TargetDir) err = zip.Extract(zipDst, opts.TargetDir)

View File

@ -15,6 +15,12 @@ func Extract(src string, dst string) error {
} }
defer zipReader.Close() defer zipReader.Close()
// create dst directory incase it does not exist.
err = os.MkdirAll(dst, 0755)
if err != nil {
return err
}
return fs.WalkDir(zipReader, ".", func(path string, d fs.DirEntry, err error) error { return fs.WalkDir(zipReader, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return err return err