flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 95f5edc1b5d2f7286e51338727592a159aaa2ae0
parent faa8c32d2c741dfa1db0a2c77cd5b1c392be8aaf
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 13 Nov 2020 00:03:40 -0800

Allow folders to exist

Diffstat:
Mhttp.go | 5+++++
Mmain.go | 2+-
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/http.go b/http.go @@ -89,6 +89,7 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { return } filePath := path.Join(c.FilesDirectory, authUser, fileName) + if r.Method == "GET" { err := checkIfValidFile(filePath, nil) if err != nil { @@ -96,6 +97,8 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { renderError(w, err.Error(), 400) return } + // create directories if dne + os.MkdirAll(path.Dir(filePath), os.ModePerm) f, err := os.OpenFile(filePath, os.O_RDONLY|os.O_CREATE, 0644) defer f.Close() fileBytes, err := ioutil.ReadAll(f) @@ -125,6 +128,8 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { renderError(w, err.Error(), 400) return } + // create directories if dne + os.MkdirAll(path.Dir(filePath), os.ModePerm) err = ioutil.WriteFile(filePath, fileBytes, 0644) if err != nil { log.Println(err) diff --git a/main.go b/main.go @@ -88,7 +88,7 @@ func getIndexFiles() ([]*File, error) { // cache this function } // make this do what it should if !info.IsDir() { - creatorFolder, _ := path.Split(thepath) + creatorFolder := strings.Split(thepath, "/")[1] updatedTime := info.ModTime() result = append(result, &File{ Name: info.Name(),