fix: add directory creation code

This commit is contained in:
이광오 2023-07-30 17:52:51 +09:00
parent f37513c45e
commit adf24fdcaa
2 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import (
) )
const PERM = 0664 const PERM = 0664
const DirPERM = 0755
// FileInfo describes a file. // FileInfo describes a file.
type FileInfo struct { type FileInfo struct {

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"path/filepath"
"strconv" "strconv"
"github.com/spf13/afero" "github.com/spf13/afero"
@ -28,6 +29,13 @@ func tusPostHandler() handleFunc {
if !d.user.Perm.Create || !d.Check(r.URL.Path) { if !d.user.Perm.Create || !d.Check(r.URL.Path) {
return http.StatusForbidden, nil return http.StatusForbidden, nil
} }
dirPath := filepath.Dir(r.URL.Path)
if _, err := d.user.Fs.Stat(dirPath); os.IsNotExist(err) {
if err := d.user.Fs.MkdirAll(dirPath, 0755); err != nil {
return http.StatusInternalServerError, err
}
}
case err != nil: case err != nil:
return errToStatus(err), err return errToStatus(err), err
} }