fix: don't remove files on unsuccessful updates (closes #1456)

pull/1499/head
Oleg Lobanov 2021-07-24 15:16:09 +02:00
parent 730be5ef6b
commit 6b19ab6613
No known key found for this signature in database
GPG Key ID: 7CC64E41212621B0
1 changed files with 10 additions and 5 deletions

View File

@ -158,12 +158,21 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
_, _ = io.Copy(ioutil.Discard, r.Body)
}()
// Only allow PUT for files.
if strings.HasSuffix(r.URL.Path, "/") {
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)
if writeErr != nil {
return writeErr
@ -174,10 +183,6 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
return nil
}, "save", r.URL.Path, "", d.user)
if err != nil {
_ = d.user.Fs.RemoveAll(r.URL.Path)
}
return errToStatus(err), err
})