add webdav move file action

This commit is contained in:
tickstep 2021-12-30 23:15:42 +08:00
parent d867267756
commit a4a74f062e
2 changed files with 39 additions and 1 deletions

View File

@ -166,5 +166,37 @@ func (p *PanClientProxy) Rename(oldpath, newpath string) error {
oldFile.FileName = path.Base(newpath)
p.cacheFilePathEntity(oldFile)
return nil
}
func (p *PanClientProxy) Move(oldpath, newpath string) error {
oldFile, er := p.cacheFilePath(oldpath)
if er != nil {
return os.ErrNotExist
}
newFileParentDir,er := p.cacheFilePath(path.Dir(newpath))
if er != nil {
return os.ErrNotExist
}
param := aliyunpan.FileMoveParam{
DriveId: p.PanDriveId,
FileId: oldFile.FileId,
ToDriveId: p.PanDriveId,
ToParentFileId: newFileParentDir.FileId,
}
params := []*aliyunpan.FileMoveParam{}
params = append(params, &param)
_,e := p.PanUser.PanClient().FileMove(params)
if e != nil {
return os.ErrInvalid
}
// invalidate parent folder cache
p.deleteOneFilesDirectoriesListCache(path.Dir(oldpath))
p.deleteOneFilesDirectoriesListCache(path.Dir(newpath))
return nil
}

View File

@ -126,7 +126,13 @@ func (d WebDavDir) Rename(ctx context.Context, oldName, newName string) error {
// Prohibit renaming from or to the virtual root directory.
return os.ErrInvalid
}
return d.panClientProxy.Rename(oldName, newName)
if path.Dir(oldName) == path.Dir(newName) {
// rename
return d.panClientProxy.Rename(oldName, newName)
} else {
// move file
return d.panClientProxy.Move(oldName, newName)
}
}
func (d WebDavDir) Stat(ctx context.Context, name string) (os.FileInfo, error) {