summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2026-01-17 02:17:20 +0200
committerMarin Ivanov <[email protected]>2026-01-17 02:17:20 +0200
commitc15274f10e3913427d438fec91e460f5db4de6ba (patch)
tree495ee791642857a8da99f4a518039f8e7e9721e6
parent858c7e8f1ff1fd4878f0276881f6048043507f9f (diff)
fixup the correct file sync close order
-rw-r--r--main.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/main.go b/main.go
index 1df5c3f..f270f13 100644
--- a/main.go
+++ b/main.go
@@ -119,14 +119,12 @@ func (s *Server) createPosting(rd io.Reader, mimeType string) (string, error) {
if err != nil {
return "", fmt.Errorf("randomFile(): %w", err)
}
- defer f.Sync()
defer f.Close()
if _, err := io.Copy(f, rd); err != nil {
return "", fmt.Errorf("io.Copy(): %w", err)
}
- m := Metadata{
- ContentType: mimeType,
- }
+ f.Sync()
+ m := Metadata{ContentType: mimeType}
if err = s.writeMetadata(name, &m); err != nil {
return "", fmt.Errorf("writeMetadata(): %w", err)
}
@@ -183,7 +181,7 @@ func (s *Server) servePosting(w http.ResponseWriter, r *http.Request, name strin
http.ServeFile(w, r, filename)
}
-func (s *Server) indexPost(w http.ResponseWriter, r *http.Request) {
+func (s *Server) post(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
return
}
@@ -236,7 +234,7 @@ func (s *Server) indexPost(w http.ResponseWriter, r *http.Request) {
}
}
-func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) {
+func (s *Server) get(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
w.Header().Add("content-type", "text/html; charset=UTF-8")
@@ -251,9 +249,9 @@ func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) {
func (s *Server) Index(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
- s.indexGet(w, r)
+ s.get(w, r)
case http.MethodPost:
- s.indexPost(w, r)
+ s.post(w, r)
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}