support webdav rename action

This commit is contained in:
tickstep 2021-12-30 23:06:02 +08:00
parent 5a88effab9
commit d867267756
2 changed files with 23 additions and 2 deletions

View File

@ -147,3 +147,24 @@ func (p *PanClientProxy) Mkdir(pathStr string, perm os.FileMode) error {
}
return fmt.Errorf("unknown error")
}
func (p *PanClientProxy) Rename(oldpath, newpath string) error {
oldFile, er := p.cacheFilePath(oldpath)
if er != nil {
return os.ErrNotExist
}
_,e := p.PanUser.PanClient().FileRename(p.PanDriveId, oldFile.FileId, path.Base(newpath))
if e != nil {
return os.ErrInvalid
}
// invalidate parent folder cache
p.deleteOneFilesDirectoriesListCache(path.Dir(oldpath))
// add new name cache
oldFile.Path = newpath
oldFile.FileName = path.Base(newpath)
p.cacheFilePathEntity(oldFile)
return nil
}

View File

@ -126,7 +126,7 @@ func (d WebDavDir) Rename(ctx context.Context, oldName, newName string) error {
// Prohibit renaming from or to the virtual root directory.
return os.ErrInvalid
}
return os.Rename(oldName, newName)
return d.panClientProxy.Rename(oldName, newName)
}
func (d WebDavDir) Stat(ctx context.Context, name string) (os.FileInfo, error) {
@ -135,7 +135,7 @@ func (d WebDavDir) Stat(ctx context.Context, name string) (os.FileInfo, error) {
fileItem,e := d.panClientProxy.FileInfoByPath(d.formatAbsoluteName(name))
if e != nil {
logger.Verboseln("file path not existed: " + d.formatAbsoluteName(name))
return nil, e
return nil, os.ErrNotExist
}
*f = NewWebDavFileInfo(fileItem)
}