Skip to content

Commit

Permalink
fix: add directory creation code to partial upload handler (#2575) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maeryo committed Jul 31, 2023
1 parent 4e28cc1 commit 912f27a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

const PERM = 0664
const DIR_PERM = 0755

Check failure on line 27 in files/file.go

View workflow job for this annotation

GitHub Actions / lint-backend

ST1003: should not use ALL_CAPS in Go names; use CamelCase instead (stylecheck)

// FileInfo describes a file.
type FileInfo struct {
Expand Down
8 changes: 8 additions & 0 deletions http/tus_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"os"
"path/filepath"
"strconv"

"github.com/spf13/afero"
Expand All @@ -28,6 +29,13 @@ func tusPostHandler() handleFunc {
if !d.user.Perm.Create || !d.Check(r.URL.Path) {
return http.StatusForbidden, nil
}

dirPath := filepath.Dir(r.URL.Path)
if _, statErr := d.user.Fs.Stat(dirPath); os.IsNotExist(statErr) {
if mkdirErr := d.user.Fs.MkdirAll(dirPath, files.DIR_PERM); mkdirErr != nil {
return http.StatusInternalServerError, err
}
}
case err != nil:
return errToStatus(err), err
}
Expand Down

0 comments on commit 912f27a

Please sign in to comment.