Pass all the move tests.
This commit is contained in:
@ -272,13 +272,13 @@ func (this *DavService) HandleMkcol(writer http.ResponseWriter, request *http.Re
|
||||
}
|
||||
|
||||
//check whether col exists. (RFC2518:8.3.1)
|
||||
dbMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, true, thisDirName)
|
||||
dbMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, TRUE, thisDirName)
|
||||
if dbMatter != nil {
|
||||
panic(result.CustomWebResult(result.METHOD_NOT_ALLOWED, fmt.Sprintf("%s already exists", dirPath)))
|
||||
}
|
||||
|
||||
//check whether file exists. (RFC2518:8.3.1)
|
||||
fileMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, false, thisDirName)
|
||||
fileMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, FALSE, thisDirName)
|
||||
if fileMatter != nil {
|
||||
panic(result.CustomWebResult(result.METHOD_NOT_ALLOWED, fmt.Sprintf("%s file already exists", dirPath)))
|
||||
}
|
||||
@ -399,15 +399,24 @@ func (this *DavService) HandleMove(writer http.ResponseWriter, request *http.Req
|
||||
fmt.Printf("MOVE %s\n", subPath)
|
||||
|
||||
srcMatter, destDirMatter, srcDirPath, destinationDirPath, destinationName, overwrite := this.prepareMoveCopy(writer, request, user, subPath)
|
||||
|
||||
//move to the new directory
|
||||
if destinationDirPath == srcDirPath {
|
||||
//if destination path not change. it means rename.
|
||||
this.matterService.AtomicRename(request, srcMatter, destinationName, user)
|
||||
this.matterService.AtomicRename(request, srcMatter, destinationName, overwrite, user)
|
||||
} else {
|
||||
this.matterService.AtomicMove(request, srcMatter, destDirMatter, overwrite, user)
|
||||
}
|
||||
|
||||
this.logger.Info("finish moving %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)
|
||||
}
|
||||
}
|
||||
|
||||
//copy file/directory
|
||||
@ -415,11 +424,6 @@ 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: 7 (copy_coll)" {
|
||||
fmt.Println("stop here")
|
||||
}
|
||||
|
||||
srcMatter, destDirMatter, _, _, destinationName, overwrite := this.prepareMoveCopy(writer, request, user, subPath)
|
||||
|
||||
//copy to the new directory
|
||||
|
@ -342,7 +342,7 @@ func (this *MatterController) Rename(writer http.ResponseWriter, request *http.R
|
||||
panic(result.UNAUTHORIZED)
|
||||
}
|
||||
|
||||
this.matterService.AtomicRename(request, matter, name, user)
|
||||
this.matterService.AtomicRename(request, matter, name, false, user)
|
||||
|
||||
return this.Success(matter)
|
||||
}
|
||||
|
@ -110,34 +110,6 @@ func (this *MatterDao) FindWithRootByPath(path string, user *User) *Matter {
|
||||
return matter
|
||||
}
|
||||
|
||||
func (this *MatterDao) FindByUserUuidAndPuuidAndNameAndDirTrue(userUuid string, puuid string, name string) *Matter {
|
||||
|
||||
var wp = &builder.WherePair{}
|
||||
|
||||
if userUuid != "" {
|
||||
wp = wp.And(&builder.WherePair{Query: "user_uuid = ?", Args: []interface{}{userUuid}})
|
||||
}
|
||||
|
||||
if puuid != "" {
|
||||
wp = wp.And(&builder.WherePair{Query: "puuid = ?", Args: []interface{}{puuid}})
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
wp = wp.And(&builder.WherePair{Query: "name = ?", Args: []interface{}{name}})
|
||||
}
|
||||
|
||||
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{1}})
|
||||
|
||||
var matter = &Matter{}
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
|
||||
|
||||
if db.Error != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return matter
|
||||
}
|
||||
|
||||
func (this *MatterDao) FindByUserUuidAndPuuidAndDirTrue(userUuid string, puuid string) []*Matter {
|
||||
|
||||
var wp = &builder.WherePair{}
|
||||
@ -202,7 +174,7 @@ func (this *MatterDao) CountByUserUuidAndPuuidAndDirAndName(userUuid string, puu
|
||||
return count
|
||||
}
|
||||
|
||||
func (this *MatterDao) FindByUserUuidAndPuuidAndDirAndName(userUuid string, puuid string, dir bool, name string) *Matter {
|
||||
func (this *MatterDao) FindByUserUuidAndPuuidAndDirAndName(userUuid string, puuid string, dir string, name string) *Matter {
|
||||
|
||||
var matter = &Matter{}
|
||||
|
||||
@ -220,7 +192,11 @@ func (this *MatterDao) FindByUserUuidAndPuuidAndDirAndName(userUuid string, puui
|
||||
wp = wp.And(&builder.WherePair{Query: "name = ?", Args: []interface{}{name}})
|
||||
}
|
||||
|
||||
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{dir}})
|
||||
if dir == TRUE {
|
||||
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{true}})
|
||||
} else if dir == FALSE {
|
||||
wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{false}})
|
||||
}
|
||||
|
||||
db := core.CONTEXT.GetDB().Where(wp.Query, wp.Args...).First(matter)
|
||||
|
||||
|
@ -474,7 +474,7 @@ func (this *MatterService) createDirectory(request *http.Request, dirMatter *Mat
|
||||
}
|
||||
|
||||
//if exist. return.
|
||||
matter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, true, name)
|
||||
matter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, TRUE, name)
|
||||
if matter != nil {
|
||||
return matter
|
||||
}
|
||||
@ -743,7 +743,9 @@ func (this *MatterService) AtomicCopy(request *http.Request, srcMatter *Matter,
|
||||
}
|
||||
|
||||
//rename matter to name
|
||||
func (this *MatterService) AtomicRename(request *http.Request, matter *Matter, name string, user *User) {
|
||||
func (this *MatterService) AtomicRename(request *http.Request, matter *Matter, name string, overwrite bool, user *User) {
|
||||
|
||||
this.logger.Info("Try to rename srcPath = %s to name = %s", matter.Path, name)
|
||||
|
||||
if user == nil {
|
||||
panic(result.BadRequest("user cannot be nil"))
|
||||
@ -758,12 +760,16 @@ func (this *MatterService) AtomicRename(request *http.Request, matter *Matter, n
|
||||
panic(result.BadRequestI18n(request, i18n.MatterNameNoChange))
|
||||
}
|
||||
|
||||
//判断同级文件夹中是否有同名的文件
|
||||
count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, matter.Puuid, matter.Dir, name)
|
||||
//check whether the name used by another matter.
|
||||
oldMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, matter.Puuid, "", name)
|
||||
if oldMatter != nil {
|
||||
if overwrite {
|
||||
//delete this one.
|
||||
this.Delete(request, oldMatter, user)
|
||||
} else {
|
||||
panic(result.CustomWebResult(result.PRECONDITION_FAILED, fmt.Sprintf("%s already exists", name)))
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
|
||||
panic(result.BadRequestI18n(request, i18n.MatterExist, name))
|
||||
}
|
||||
|
||||
if matter.Dir {
|
||||
@ -859,7 +865,7 @@ func (this *MatterService) mirror(request *http.Request, srcPath string, destDir
|
||||
if fileStat.IsDir() {
|
||||
|
||||
//判断当前文件夹下,文件是否已经存在了。
|
||||
srcDirMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, destDirMatter.Uuid, true, fileStat.Name())
|
||||
srcDirMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, destDirMatter.Uuid, TRUE, fileStat.Name())
|
||||
|
||||
if srcDirMatter == nil {
|
||||
srcDirMatter = this.createDirectory(request, destDirMatter, fileStat.Name(), user)
|
||||
@ -878,7 +884,7 @@ func (this *MatterService) mirror(request *http.Request, srcPath string, destDir
|
||||
} else {
|
||||
|
||||
//判断当前文件夹下,文件是否已经存在了。
|
||||
matter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, destDirMatter.Uuid, false, fileStat.Name())
|
||||
matter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, destDirMatter.Uuid, FALSE, fileStat.Name())
|
||||
if matter != nil {
|
||||
//如果是覆盖,那么删除之前的文件
|
||||
if overwrite {
|
||||
|
Reference in New Issue
Block a user