Skip to content

Commit

Permalink
cleanup files in case of a failure
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jun 9, 2018
1 parent 4f6b968 commit 1affd61
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server/hdl_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -202,18 +202,21 @@ 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
}

_, 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
}
Expand Down

0 comments on commit 1affd61

Please sign in to comment.