Fix some copy warning.

This commit is contained in:
zicla
2020-03-12 00:56:54 +08:00
parent fc2df7e501
commit bea9a0a56d
4 changed files with 28 additions and 3 deletions

View File

@ -383,7 +383,11 @@ func (this *DavService) prepareMoveCopy(
panic(result.BadRequest("you cannot move the root directory"))
}
destDirMatter = this.matterDao.CheckWithRootByPath(destinationDirPath, user)
destDirMatter = this.matterDao.FindWithRootByPath(destinationDirPath, user)
if destDirMatter == nil {
//throw conflict error
panic(result.CustomWebResult(result.CONFLICT, fmt.Sprintf("%s not exist", destinationDirPath)))
}
return srcMatter, destDirMatter, srcDirPath, destinationDirPath, destinationName, overwrite
@ -411,6 +415,11 @@ func (this *DavService) HandleCopy(writer http.ResponseWriter, request *http.Req
fmt.Printf("COPY %s\n", subPath)
//debug point
if request.Header.Get("X-Litmus") == "copymove: 5 (copy_nodestcoll)" {
fmt.Println("stop here")
}
srcMatter, destDirMatter, _, _, destinationName, overwrite := this.prepareMoveCopy(writer, request, user, subPath)
//copy to the new directory
@ -418,6 +427,14 @@ func (this *DavService) HandleCopy(writer http.ResponseWriter, request *http.Req
this.logger.Info("finish copying %s => %s", subPath, destDirMatter.Path)
if overwrite {
//overwrite old. set the status code 204
writer.WriteHeader(http.StatusNoContent)
} else {
//copy new. set the status code 201
writer.WriteHeader(http.StatusCreated)
}
}
//lock.

View File

@ -528,7 +528,8 @@ func (this *MatterService) handleOverwrite(request *http.Request, user *User, de
//delete.
this.Delete(request, destMatter, user)
} else {
panic(result.BadRequestI18n(request, i18n.MatterExist, destMatter.Path))
//throw precondition failed. (RFC4918:10.6)
panic(result.CustomWebResult(result.PRECONDITION_FAILED, fmt.Sprintf("%s exists", destMatter.Path)))
}
}