Skip to content

Commit

Permalink
Fix some copy warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
zicla committed Mar 11, 2020
1 parent fc2df7e commit bea9a0a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
19 changes: 18 additions & 1 deletion code/rest/dav_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -411,13 +415,26 @@ 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
this.matterService.AtomicCopy(request, srcMatter, destDirMatter, destinationName, overwrite, user)

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.
Expand Down
3 changes: 2 additions & 1 deletion code/rest/matter_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

Expand Down
3 changes: 3 additions & 0 deletions code/tool/result/web_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion code/tool/util/util_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func GetFilenameOfPath(fullPath string) string {
func DeleteEmptyDir(dirPath string) bool {
dir, err := ioutil.ReadDir(dirPath)
if err != nil {
panic(result.BadRequest("occur error while reading %s %s", dirPath, err.Error()))
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
Expand Down

0 comments on commit bea9a0a

Please sign in to comment.