Skip to content

Commit

Permalink
feat: 不允许把目录复制到原目录中
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 26, 2024
1 parent b2845fb commit 2af4b95
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func (s *FileService) Move(w http.ResponseWriter, r *http.Request) {
return
}

if io.IsDir(req.Source) && strings.HasPrefix(req.Target, req.Source) {
Error(w, http.StatusForbidden, "你不能这样做,会玩坏的")
return
}

if err = io.Mv(req.Source, req.Target); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
Expand All @@ -199,6 +204,11 @@ func (s *FileService) Copy(w http.ResponseWriter, r *http.Request) {
return
}

if io.IsDir(req.Source) && strings.HasPrefix(req.Target, req.Source) {
Error(w, http.StatusForbidden, "你不能这样做,会玩坏的")
return
}

if err = io.Cp(req.Source, req.Target); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
Expand Down

0 comments on commit 2af4b95

Please sign in to comment.