From e38520c0b0edf449fe3f48245c48d21ab34891f6 Mon Sep 17 00:00:00 2001 From: zicla Date: Wed, 17 Jan 2018 20:10:20 +0800 Subject: [PATCH] Folder cannot move to itself. fix #8 --- rest/config.go | 2 +- rest/matter_controller.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rest/config.go b/rest/config.go index b9126d8..391ea32 100644 --- a/rest/config.go +++ b/rest/config.go @@ -152,7 +152,7 @@ func PrepareConfigs() { filePath := GetConfPath() + "/tank.json" content, err := ioutil.ReadFile(filePath) if err != nil { - LogWarning(fmt.Sprintf("无法找到配置文件,使用默认配置项:%s,%v", filePath, err)) + LogWarning(fmt.Sprintf("无法找到配置文件:%s,错误:%v\n将使用config.go中的默认配置项。", filePath, err)) } else { // 用 json.Unmarshal err := json.Unmarshal(content, CONFIG) diff --git a/rest/matter_controller.go b/rest/matter_controller.go index 736e72a..30dd679 100644 --- a/rest/matter_controller.go +++ b/rest/matter_controller.go @@ -410,7 +410,7 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req return this.Error("destUuid参数必填") } else { if destUuid != "root" { - destMatter = this.matterDao.FindByUuid(destUuid) + destMatter = this.matterService.Detail(destUuid) if user.Role != USER_ROLE_ADMINISTRATOR && destMatter.UserUuid != user.Uuid { return this.Error(RESULT_CODE_UNAUTHORIZED) @@ -422,7 +422,7 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req //验证src是否有问题。 for _, uuid := range srcUuids { //找出该文件或者文件夹 - srcMatter := this.matterDao.FindByUuid(uuid) + srcMatter := this.matterDao.CheckByUuid(uuid) if user.Role != USER_ROLE_ADMINISTRATOR && srcMatter.UserUuid != user.Uuid { return this.Error(RESULT_CODE_UNAUTHORIZED) @@ -444,6 +444,16 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req if srcMatter.UserUuid != destMatter.UserUuid { panic("文件和目标文件夹的拥有者不是同一人") } + + //文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。 + tmpMatter := destMatter + for tmpMatter != nil { + if uuid == tmpMatter.Uuid { + panic("文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。") + } + tmpMatter = tmpMatter.Parent + } + } srcMatters = append(srcMatters, srcMatter)