Skip to content

Commit

Permalink
fix: create a subfolder in model-repository if needed (#290)
Browse files Browse the repository at this point in the history
Because

- need to create a subfolder `users` when creating a model in
`model-repository`

This commit

- add code to check parent folder and create it if not existed
- close #288
  • Loading branch information
Phelan164 committed Feb 24, 2023
1 parent 0ece797 commit 7f8d78b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func Unzip(filePath string, dstDir string, owner string, uploadedModel *datamode
if err := ValidateFilePath(filePath); err != nil {
return "", "", err
}
// ensure the parent folder existed
if _, err := os.Stat(filepath.Base(filePath)); os.IsNotExist(err) {
if err := os.MkdirAll(filePath, os.ModePerm); err != nil {
return "", "", err
}
}

dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return "", "", err
Expand Down

0 comments on commit 7f8d78b

Please sign in to comment.