From 3d87c6244f5aef8508c790ce95ba031b4a1ca200 Mon Sep 17 00:00:00 2001 From: tickstep Date: Sat, 8 Mar 2025 10:14:12 +0800 Subject: [PATCH] fix local windows path recognize error --- internal/command_local/lcd.go | 2 +- internal/command_local/lls.go | 9 +-------- internal/command_local/utils.go | 5 +++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/command_local/lcd.go b/internal/command_local/lcd.go index f6518ce..936202b 100644 --- a/internal/command_local/lcd.go +++ b/internal/command_local/lcd.go @@ -77,7 +77,7 @@ func CmdLocalPwd() cli.Command { // Unix-like system, so just assume Unix lwd = strings.ReplaceAll(lwd, "\\", "/") } - fmt.Println(lwd) + fmt.Println("本地工作目录: " + lwd) return nil }, } diff --git a/internal/command_local/lls.go b/internal/command_local/lls.go index 1418efe..e5fa764 100644 --- a/internal/command_local/lls.go +++ b/internal/command_local/lls.go @@ -28,13 +28,6 @@ import ( "strings" ) -type () - -const ( - opLs int = iota - opSearch -) - func CmdLocalLs() cli.Command { return cli.Command{ Name: "lls", @@ -216,7 +209,7 @@ func renderTable(path string, files []os.FileInfo) { totalSize += file.Size() tb.Append([]string{strconv.Itoa(k + 1), converter.ConvertFileSize(file.Size(), 2), file.ModTime().Format("2006-01-02 15:04:05"), file.Name()}) } - tb.Append([]string{"", "总大小: " + converter.ConvertFileSize(totalSize, 2), "", fmt.Sprintf("文件总数: %d, 目录总数: %d", fileCount, dirCount)}) + tb.Append([]string{"", "总: " + converter.ConvertFileSize(totalSize, 2), "", fmt.Sprintf("文件总数: %d, 目录总数: %d", fileCount, dirCount)}) fmt.Printf("\n本地当前目录: %s\n", path) fmt.Printf("----\n") diff --git a/internal/command_local/utils.go b/internal/command_local/utils.go index 44bfd6f..7978a45 100644 --- a/internal/command_local/utils.go +++ b/internal/command_local/utils.go @@ -5,6 +5,7 @@ import ( "github.com/tickstep/aliyunpan/library/homedir" "os" "path" + "path/filepath" "strings" ) @@ -19,8 +20,8 @@ func getLocalHomeDir() string { // localPathJoin 拼接本地路径 func localPathJoin(p string) string { - p = strings.ReplaceAll(p, "\\", "/") - if path.IsAbs(p) { + p = path.Clean(strings.ReplaceAll(p, "\\", "/")) + if filepath.IsAbs(p) { return p } else if strings.HasPrefix(p, "~") { if d, e := homedir.Expand(p); e == nil {