all repos — flounder @ 32fd85e62324db1a34b5e78e1ef7b61cee31edde

A small site builder for the Gemini protocol

Don't create file until save
alex wennerberg alex@alexwennerberg.com
Wed, 18 Nov 2020 19:21:32 -0800
commit

32fd85e62324db1a34b5e78e1ef7b61cee31edde

parent

73cee727f63bc89ce49772003f5a61a79f98af8d

2 files changed, 9 insertions(+), 5 deletions(-)

jump to
M http.gohttp.go

@@ -98,10 +98,15 @@ 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) + f, err := os.OpenFile(filePath, os.O_RDONLY, 0644) + var fileBytes []byte + if os.IsNotExist(err) { + fileBytes = []byte{} + err = nil + } else { + defer f.Close() + fileBytes, err = ioutil.ReadAll(f) + } if err != nil { log.Println(err) renderError(w, InternalServerErrorMsg, 500)
M main.gomain.go

@@ -91,7 +91,6 @@

func getCreator(filePath string) string { l := len(strings.Split(c.FilesDirectory, "/")) r := strings.Split(filePath, "/")[l] - fmt.Println(filePath, c.FilesDirectory, r) return r }