fix: don't remove files on unsuccessful updates (closes
@@ -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
})
