all repos — flounder @ 95f5edc1b5d2f7286e51338727592a159aaa2ae0

A small site builder for the Gemini protocol

Allow folders to exist
alex wennerberg alex@alexwennerberg.com
Fri, 13 Nov 2020 00:03:40 -0800
commit

95f5edc1b5d2f7286e51338727592a159aaa2ae0

parent

faa8c32d2c741dfa1db0a2c77cd5b1c392be8aaf

2 files changed, 6 insertions(+), 1 deletions(-)

jump to
M http.gohttp.go

@@ -89,6 +89,7 @@ renderError(w, "Not a text file, cannot be edited here", 400) // correct status code?

return } filePath := path.Join(c.FilesDirectory, authUser, fileName) + if r.Method == "GET" { err := checkIfValidFile(filePath, nil) if err != nil {

@@ -96,6 +97,8 @@ log.Println(err)

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 @@ log.Println(err)

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)
M main.gomain.go

@@ -88,7 +88,7 @@ return err // think about

} // 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(),