Skip to content

Commit 7d682ff

Browse files
committed
Merge pull request #278 from petertseng/downloads
Download: Create files with 0644, support directory structures
2 parents 113a259 + a7b39b6 commit 7d682ff

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

cmd/download.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ func Download(ctx *cli.Context) {
3939
}
4040

4141
for name, contents := range submission.ProblemFiles {
42-
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, name), []byte(contents), 0755); err != nil {
42+
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, name), []byte(contents), 0644); err != nil {
4343
log.Fatalf("Unable to write file %s: %s", name, err)
4444
}
4545
}
4646

4747
for name, contents := range submission.SolutionFiles {
4848
filename := strings.TrimPrefix(name, strings.ToLower("/"+submission.TrackID+"/"+submission.Slug+"/"))
49-
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, filename), []byte(contents), 0755); err != nil {
49+
dir := filepath.Dir(filename)
50+
if err := os.MkdirAll(fmt.Sprintf("%s/%s", path, dir), 0755); err != nil {
51+
log.Fatal(err)
52+
}
53+
if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, filename), []byte(contents), 0644); err != nil {
5054
log.Fatalf("Unable to write file %s: %s", name, err)
5155
}
5256
}

0 commit comments

Comments
 (0)