Add option to recursively delete a folder.

This commit is contained in:
Chris Lu
2014-04-17 22:33:21 -07:00
parent e378f9892d
commit 83c0c9843d
4 changed files with 47 additions and 8 deletions

View File

@@ -21,7 +21,7 @@ func NewFilerServer(r *http.ServeMux, port int, master string, dir string, colle
port: ":" + strconv.Itoa(port),
}
if fs.filer, err = filer.NewFilerEmbedded(dir); err != nil {
if fs.filer, err = filer.NewFilerEmbedded(master, dir); err != nil {
glog.Fatal("Can not start filer in dir", dir, ": ", err.Error())
return
}

View File

@@ -171,11 +171,14 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
}
}
// curl -X DELETE http://localhost:8888/path/to
// curl -X DELETE http://localhost:8888/path/to?recursive=true
func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
var err error
var fid string
if strings.HasSuffix(r.URL.Path, "/") {
err = fs.filer.DeleteDirectory(r.URL.Path)
isRecursive := r.FormValue("recursive") == "true"
err = fs.filer.DeleteDirectory(r.URL.Path, isRecursive)
} else {
fid, err = fs.filer.DeleteFile(r.URL.Path)
if err == nil {