fix file name auto complete issue

This commit is contained in:
tickstep 2021-10-31 15:53:27 +08:00
parent 53bdf34691
commit bf26202290
7 changed files with 32 additions and 3 deletions

View File

@ -68,6 +68,9 @@ func RunMkdir(driveId, name string) {
if rs.FileId != "" {
fmt.Println("创建文件夹成功: ", fullpath)
// cache
activeUser.DeleteCache(GetAllPathFolderByPath(fullpath))
} else {
fmt.Println("创建文件夹失败: ", fullpath)
}

View File

@ -64,6 +64,7 @@ func CmdMv() cli.Command {
// RunMove 执行移动文件/目录
func RunMove(driveId string, paths ...string) {
activeUser := GetActiveUser()
cacheCleanPaths := []string{}
opFileList, targetFile, _, err := getFileInfo(driveId, paths...)
if err != nil {
fmt.Println(err)
@ -77,6 +78,7 @@ func RunMove(driveId string, paths ...string) {
fmt.Println("没有有效的文件可移动")
return
}
cacheCleanPaths = append(cacheCleanPaths, targetFile.Path)
failedMoveFiles := []*aliyunpan.FileEntity{}
moveFileParamList := []*aliyunpan.FileMoveParam{}
@ -90,6 +92,7 @@ func RunMove(driveId string, paths ...string) {
ToDriveId: driveId,
ToParentFileId: targetFile.FileId,
})
cacheCleanPaths = append(cacheCleanPaths, path.Dir(mfi.Path))
}
fmr,er := activeUser.PanClient().FileMove(moveFileParamList)
@ -108,6 +111,7 @@ func RunMove(driveId string, paths ...string) {
}
if er == nil {
fmt.Println("操作成功, 已移动文件到目标目录: ", targetFile.Path)
activeUser.DeleteCache(cacheCleanPaths)
} else {
fmt.Println("无法移动文件,请稍后重试")
}

View File

@ -102,4 +102,5 @@ func RunRename(driveId string, oldName string, newName string) {
return
}
fmt.Printf("重命名文件成功:%s -> %s\n", path.Base(oldName), path.Base(newName))
activeUser.DeleteOneCache(path.Dir(newName))
}

View File

@ -73,6 +73,7 @@ func CmdRm() cli.Command {
func RunRemove(driveId string, paths ...string) {
activeUser := GetActiveUser()
cacheCleanDirs := []string{}
failedRmPaths := make([]string, 0, len(paths))
delFileInfos := []*aliyunpan.FileBatchActionParam{}
fileId2FileEntity := map[string]*aliyunpan.FileEntity{}
@ -90,6 +91,7 @@ func RunRemove(driveId string, paths ...string) {
FileId:fe.FileId,
})
fileId2FileEntity[fe.FileId] = fe
cacheCleanDirs = append(cacheCleanDirs, path.Dir(fe.Path))
}
// delete
@ -116,6 +118,7 @@ func RunRemove(driveId string, paths ...string) {
if len(successDelFileEntity) > 0 {
fmt.Println("操作成功, 以下文件/目录已删除, 可在云盘文件回收站找回: ")
pnt()
activeUser.DeleteCache(cacheCleanDirs)
}
if len(successDelFileEntity) == 0 && err != nil {

View File

@ -442,7 +442,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
tb.Render()
}
}
activeUser.DeleteCache(GetAllPathFolderByPath(savePath))
}
// 是否是排除上传的文件

View File

@ -92,4 +92,16 @@ func RandomStr(count int) string {
str.WriteByte(byte(STR_SET[rand.Intn(len(STR_SET))]))
}
return str.String()
}
func GetAllPathFolderByPath(pathStr string) []string {
dirNames := strings.Split(pathStr, "/")
dirs := []string{}
p := "/"
dirs = append(dirs, p)
for _,s := range dirNames {
p = path.Join(p, s)
dirs = append(dirs, p)
}
return dirs
}

View File

@ -8,8 +8,8 @@ import (
"time"
)
// deleteCache 删除含有 dirs 的缓存
func (pu *PanUser) deleteCache(dirs []string) {
// DeleteCache 删除含有 dirs 的缓存
func (pu *PanUser) DeleteCache(dirs []string) {
cache := pu.cacheOpMap.LazyInitCachePoolOp(pu.ActiveDriveId)
for _, v := range dirs {
key := v + "_" + "OrderByName"
@ -20,6 +20,12 @@ func (pu *PanUser) deleteCache(dirs []string) {
}
}
// DeleteOneCache 删除缓存
func (pu *PanUser) DeleteOneCache(dirPath string) {
ps := []string{dirPath}
pu.DeleteCache(ps)
}
// CacheFilesDirectoriesList 缓存获取
func (pu *PanUser) CacheFilesDirectoriesList(pathStr string) (fdl aliyunpan.FileList, apiError *apierror.ApiError) {
data := pu.cacheOpMap.CacheOperation(pu.ActiveDriveId, pathStr+"_OrderByName", func() expires.DataExpires {