2022-06-28 13:49:32 +08:00
|
|
|
package localfile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/tickstep/aliyunpan/internal/utils"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMyWalkFile(t *testing.T) {
|
|
|
|
count := 0
|
|
|
|
walkFunc := func(file SymlinkFile, fi os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
count += 1
|
|
|
|
fmt.Println("file: ", utils.ObjectToJsonStr(file, false))
|
|
|
|
//fmt.Println("file: ", file)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//curPath := "D:\\smb\\feny\\goprojects\\dev\\lks"
|
2022-07-02 07:27:49 +08:00
|
|
|
curPath := "/Volumes/Downloads/dev/lks"
|
2022-06-28 13:49:32 +08:00
|
|
|
file := NewSymlinkFile(curPath)
|
|
|
|
if err := WalkAllFile(file, walkFunc); err != nil {
|
|
|
|
if err != filepath.SkipDir {
|
|
|
|
fmt.Printf("警告: 遍历错误: %s\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("count: ", count)
|
|
|
|
}
|
2022-07-02 07:27:49 +08:00
|
|
|
|
|
|
|
func TestRetrieveRealPath(t *testing.T) {
|
|
|
|
curPath := "/Volumes/Downloads/dev/lks/test"
|
|
|
|
file := NewSymlinkFile(curPath)
|
|
|
|
sf, _, e := RetrieveRealPath(file)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
fmt.Println(sf)
|
|
|
|
}
|
2022-07-03 07:45:40 +08:00
|
|
|
|
|
|
|
func TestRetrieveRealPathFromLogicPath(t *testing.T) {
|
|
|
|
curPath := "/Volumes/Downloads/dev/lks/test/未命名文件夹cmd/sync_drive_config.json"
|
|
|
|
sf, _, e := RetrieveRealPathFromLogicPath(curPath)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
fmt.Println(sf)
|
|
|
|
}
|
2022-07-03 10:32:39 +08:00
|
|
|
|
|
|
|
func TestRetrieveRealPathFromLogicSuffixPath(t *testing.T) {
|
|
|
|
rootPath := NewSymlinkFile("/Volumes/Downloads/dev/测试同步盘/new_lks")
|
|
|
|
rootPath, _, _ = RetrieveRealPath(rootPath)
|
|
|
|
suffixPath := "test/未命名文件夹cmd/sync_drive_config.json"
|
|
|
|
sf, _, e := RetrieveRealPathFromLogicSuffixPath(rootPath, suffixPath)
|
|
|
|
if e != nil {
|
|
|
|
fmt.Println(e)
|
|
|
|
}
|
|
|
|
fmt.Println(sf)
|
|
|
|
}
|