From 1affd613231bebecc80ac089556d73dbe152e828 Mon Sep 17 00:00:00 2001 From: or-else Date: Sat, 9 Jun 2018 21:33:38 +0300 Subject: [PATCH] cleanup files in case of a failure --- server/hdl_files.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/hdl_files.go b/server/hdl_files.go index e5cd70403..a030cc3d1 100644 --- a/server/hdl_files.go +++ b/server/hdl_files.go @@ -33,7 +33,7 @@ import ( ) func largeFileServe(wrt http.ResponseWriter, req *http.Request) { - log.Println("Request to download file", req.URL) + log.Println("Request to download file", req.URL.Path) now := time.Now().UTC().Round(time.Millisecond) enc := json.NewEncoder(wrt) @@ -202,9 +202,10 @@ func largeFileUpload(wrt http.ResponseWriter, req *http.Request) { writeHttpResponse(nil) return } - defer outfile.Close() if err = store.Files.StartUpload(&fdef); err != nil { + outfile.Close() + os.Remove(fdef.Location) log.Println("Failed to create file record", fdef.Id, err) writeHttpResponse(decodeStoreError(err, "", "", now, nil)) return @@ -212,8 +213,10 @@ func largeFileUpload(wrt http.ResponseWriter, req *http.Request) { _, err = io.Copy(outfile, file) log.Println("Finished upload", fdef.Location) + outfile.Close() if err != nil { store.Files.FinishUpload(fdef.Id, false) + os.Remove(fdef.Location) writeHttpResponse(nil) return }