Skip to content

Commit

Permalink
fix file name auto complete issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tickstep committed Oct 31, 2021
1 parent 53bdf34 commit bf26202
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions internal/command/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func RunMkdir(driveId, name string) {

if rs.FileId != "" {
fmt.Println("创建文件夹成功: ", fullpath)

// cache
activeUser.DeleteCache(GetAllPathFolderByPath(fullpath))
} else {
fmt.Println("创建文件夹失败: ", fullpath)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/command/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -77,6 +78,7 @@ func RunMove(driveId string, paths ...string) {
fmt.Println("没有有效的文件可移动")
return
}
cacheCleanPaths = append(cacheCleanPaths, targetFile.Path)

failedMoveFiles := []*aliyunpan.FileEntity{}
moveFileParamList := []*aliyunpan.FileMoveParam{}
Expand All @@ -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)

Expand All @@ -108,6 +111,7 @@ func RunMove(driveId string, paths ...string) {
}
if er == nil {
fmt.Println("操作成功, 已移动文件到目标目录: ", targetFile.Path)
activeUser.DeleteCache(cacheCleanPaths)
} else {
fmt.Println("无法移动文件,请稍后重试")
}
Expand Down
1 change: 1 addition & 0 deletions internal/command/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
3 changes: 3 additions & 0 deletions internal/command/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
tb.Render()
}
}

activeUser.DeleteCache(GetAllPathFolderByPath(savePath))
}

// 是否是排除上传的文件
Expand Down
12 changes: 12 additions & 0 deletions internal/command/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions internal/config/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down

0 comments on commit bf26202

Please sign in to comment.