fix: don't remove files on unsuccessful updates (closes #1456)
parent
730be5ef6b
commit
6b19ab6613
|
@ -158,12 +158,21 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
|
||||||
_, _ = io.Copy(ioutil.Discard, r.Body)
|
_, _ = io.Copy(ioutil.Discard, r.Body)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
||||||
// Only allow PUT for files.
|
// Only allow PUT for files.
|
||||||
if strings.HasSuffix(r.URL.Path, "/") {
|
if strings.HasSuffix(r.URL.Path, "/") {
|
||||||
return http.StatusMethodNotAllowed, nil
|
return http.StatusMethodNotAllowed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := d.RunHook(func() error {
|
exists, err := afero.Exists(d.user.Fs, r.URL.Path)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return http.StatusNotFound, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.RunHook(func() error {
|
||||||
info, writeErr := writeFile(d.user.Fs, r.URL.Path, r.Body)
|
info, writeErr := writeFile(d.user.Fs, r.URL.Path, r.Body)
|
||||||
if writeErr != nil {
|
if writeErr != nil {
|
||||||
return writeErr
|
return writeErr
|
||||||
|
@ -174,10 +183,6 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
|
||||||
return nil
|
return nil
|
||||||
}, "save", r.URL.Path, "", d.user)
|
}, "save", r.URL.Path, "", d.user)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
_ = d.user.Fs.RemoveAll(r.URL.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return errToStatus(err), err
|
return errToStatus(err), err
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue