Skip to content

Commit

Permalink
fix: don't remove files on unsuccessful updates (closes #1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
o1egl committed Jul 24, 2021
1 parent 730be5e commit 6b19ab6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions http/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})

Expand Down

0 comments on commit 6b19ab6

Please sign in to comment.