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)))
}
}

View File

@ -33,6 +33,7 @@ var (
NOT_FOUND = &CodeWrapper{Code: "NOT_FOUND", HttpStatus: http.StatusNotFound, Description: "404 not found"}
METHOD_NOT_ALLOWED = &CodeWrapper{Code: "METHOD_NOT_ALLOWED", HttpStatus: http.StatusMethodNotAllowed, Description: "405 method not allowed"}
CONFLICT = &CodeWrapper{Code: "CONFLICT", HttpStatus: http.StatusConflict, Description: "409 conflict"}
PRECONDITION_FAILED = &CodeWrapper{Code: "PRECONDITION_FAILED", HttpStatus: http.StatusPreconditionFailed, Description: "412 precondition failed"}
UNSUPPORTED_MEDIA_TYPE = &CodeWrapper{Code: "UNSUPPORTED_MEDIA_TYPE", HttpStatus: http.StatusUnsupportedMediaType, Description: "415 conflict"}
RANGE_NOT_SATISFIABLE = &CodeWrapper{Code: "RANGE_NOT_SATISFIABLE", HttpStatus: http.StatusRequestedRangeNotSatisfiable, Description: "range not satisfiable"}
NOT_INSTALLED = &CodeWrapper{Code: "NOT_INSTALLED", HttpStatus: http.StatusInternalServerError, Description: "application not installed"}
@ -61,6 +62,8 @@ func FetchHttpStatus(code string) int {
return METHOD_NOT_ALLOWED.HttpStatus
} else if code == CONFLICT.Code {
return CONFLICT.HttpStatus
} else if code == PRECONDITION_FAILED.Code {
return PRECONDITION_FAILED.HttpStatus
} else if code == UNSUPPORTED_MEDIA_TYPE.Code {
return UNSUPPORTED_MEDIA_TYPE.HttpStatus
} else if code == RANGE_NOT_SATISFIABLE.Code {

View File

@ -128,8 +128,12 @@ func GetFilenameOfPath(fullPath string) string {
func DeleteEmptyDir(dirPath string) bool {
dir, err := ioutil.ReadDir(dirPath)
if err != nil {
if strings.Contains(err.Error(), "The system cannot find") {
return false
} else {
panic(result.BadRequest("occur error while reading %s %s", dirPath, err.Error()))
}
}
if len(dir) == 0 {
//empty dir
err = os.Remove(dirPath)