コード例 #1
0
ファイル: common.go プロジェクト: netroby/seaweedfs
func deleteForClientHandler(w http.ResponseWriter, r *http.Request, masterUrl string) {
	r.ParseForm()
	fids := r.Form["fid"]
	ret, err := operation.DeleteFiles(masterUrl, fids)
	if err != nil {
		writeJsonError(w, r, http.StatusInternalServerError, err)
		return
	}
	writeJsonQuiet(w, r, http.StatusAccepted, ret)
}
コード例 #2
0
ファイル: filer_embedded.go プロジェクト: netroby/seaweedfs
func (filer *FilerEmbedded) DeleteDirectory(dirPath string, recursive bool) (err error) {
	dirId, e := filer.directories.FindDirectory(dirPath)
	if e != nil {
		return e
	}
	if sub_dirs, sub_err := filer.directories.ListDirectories(dirPath); sub_err == nil {
		if len(sub_dirs) > 0 && !recursive {
			return fmt.Errorf("Fail to delete directory %s: %d sub directories found!", dirPath, len(sub_dirs))
		}
		for _, sub := range sub_dirs {
			if delete_sub_err := filer.DeleteDirectory(filepath.Join(dirPath, sub.Name), recursive); delete_sub_err != nil {
				return delete_sub_err
			}
		}
	}
	list := filer.files.ListFiles(dirId, "", 100)
	if len(list) != 0 && !recursive {
		if !recursive {
			return fmt.Errorf("Fail to delete non-empty directory %s!", dirPath)
		}
	}
	for {
		if len(list) == 0 {
			return filer.directories.DeleteDirectory(dirPath)
		}
		var fids []string
		for _, fileEntry := range list {
			fids = append(fids, string(fileEntry.Id))
		}
		if result_list, delete_file_err := operation.DeleteFiles(filer.master, fids); delete_file_err != nil {
			return delete_file_err
		} else {
			if len(result_list.Errors) > 0 {
				return errors.New(strings.Join(result_list.Errors, "\n"))
			}
		}
		lastFile := list[len(list)-1]
		list = filer.files.ListFiles(dirId, lastFile.Name, 100)
	}

}