Skip to content

Commit b6200a8

Browse files
committed
support delete non-empty folder, close #97
1 parent 1618440 commit b6200a8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

httpstaticserver.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,16 @@ func (s *HTTPStaticServer) hMkdir(w http.ResponseWriter, req *http.Request) {
158158
}
159159

160160
func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) {
161-
// only can delete file now
162161
path := mux.Vars(req)["path"]
162+
path = filepath.Clean(path) // for safe reason, prevent path contain ..
163163
auth := s.readAccessConf(path)
164164
if !auth.canDelete(req) {
165165
http.Error(w, "Delete forbidden", http.StatusForbidden)
166166
return
167167
}
168168

169-
err := os.Remove(filepath.Join(s.Root, path))
169+
// TODO: path safe check
170+
err := os.RemoveAll(filepath.Join(s.Root, path))
170171
if err != nil {
171172
pathErr, ok := err.(*os.PathError)
172173
if ok {
@@ -232,7 +233,7 @@ func (s *HTTPStaticServer) hUploadOrMkdir(w http.ResponseWriter, req *http.Reque
232233

233234
// Large file (>32MB) will store in tmp directory
234235
// The quickest operation is call os.Move instead of os.Copy
235-
// Note: it seems not working well
236+
// Note: it seems not working well, os.Rename might be failed
236237

237238
var copyErr error
238239
// if osFile, ok := file.(*os.File); ok && fileExists(osFile.Name()) {

0 commit comments

Comments
 (0)