Skip to content

Commit

Permalink
fix: Get filepath for checking overwrite
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 27, 2024
1 parent 49a695f commit f77bfd7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/crud/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ func (s Service) handleMultipart(w http.ResponseWriter, r *http.Request, request
}

if values["overwrite"] != "true" {
fileName, err := safeFilename(values["filename"])
_, filePath, err := getUploadNameAndPath(request, values["filename"], file)
if err != nil {
s.error(w, r, request, model.WrapInvalid(err))
return
}

if _, err := s.storage.Stat(ctx, request.SubPath(fileName)); err == nil {
s.error(w, r, request, model.WrapInvalid(fmt.Errorf("filename `%s`: %w", fileName, ErrFileAlreadyExists)))
if _, err := s.storage.Stat(ctx, filePath); err == nil {
s.error(w, r, request, model.WrapInvalid(fmt.Errorf("filename `%s`: %w", filePath, ErrFileAlreadyExists)))
return
}
}
Expand Down

0 comments on commit f77bfd7

Please sign in to comment.