refactor common pattern of close & remove temporary file into calling the new store.CloseRemoveTempFile

This commit is contained in:
Mechiel Lukkien
2023-11-01 18:57:38 +01:00
parent b6897d1837
commit ef50f4abf0
11 changed files with 15 additions and 81 deletions

View File

@ -299,11 +299,7 @@ func Handle(w http.ResponseWriter, r *http.Request) {
}
defer func() {
if tmpf != nil {
name := tmpf.Name()
err := tmpf.Close()
log.Check(err, "closing uploaded file")
err = os.Remove(name)
log.Check(err, "removing temporary file", mlog.Field("path", name))
store.CloseRemoveTempFile(log, tmpf, "upload")
}
}()
if _, err := io.Copy(tmpf, f); err != nil {