-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_path.go
102 lines (85 loc) · 1.87 KB
/
common_path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package support
import (
"os"
"strings"
"github.com/bitwormhole/afs"
)
type myCommonPath struct {
fs afs.FS
path string
}
func (inst *myCommonPath) _Impl() afs.Path {
return inst
}
func (inst *myCommonPath) GetFS() afs.FS {
return inst.fs
}
func (inst *myCommonPath) GetParent() afs.Path {
path := inst.path
return inst.fs.NewPath(path + "/..")
}
func (inst *myCommonPath) GetChild(name string) afs.Path {
path := inst.path
return inst.fs.NewPath(path + "/" + name)
}
func (inst *myCommonPath) String() string {
return inst.path
}
func (inst *myCommonPath) GetName() string {
sep := inst.fs.Separator()
path := inst.path
index := strings.LastIndex(path, sep)
if index > 0 {
return path[index+1:]
}
return ""
}
func (inst *myCommonPath) GetInfo() afs.FileInfo {
info := &myCommonFileInfo{}
info.load(inst)
return info
}
func (inst *myCommonPath) GetIO() afs.FileIO {
return &myCommonFileIO{path: inst}
}
func (inst *myCommonPath) Mkdir(op afs.Options) error {
path := inst.path
return os.Mkdir(path, op.Permission)
}
func (inst *myCommonPath) Mkdirs(op afs.Options) error {
path := inst.path
return os.MkdirAll(path, op.Permission)
}
func (inst *myCommonPath) Delete() error {
return os.Remove(inst.path)
}
func (inst *myCommonPath) ListNames() []string {
file, err := os.Open(inst.path)
if err != nil {
return []string{}
}
defer file.Close()
names, err := file.Readdirnames(0)
if err != nil {
return []string{}
}
return names
}
func (inst *myCommonPath) ListPaths() []string {
names := inst.ListNames()
dst := make([]string, 0)
for _, name := range names {
child := inst.GetChild(name)
dst = append(dst, child.String())
}
return dst
}
func (inst *myCommonPath) ListChildren() []afs.Path {
names := inst.ListNames()
dst := make([]afs.Path, 0)
for _, name := range names {
child := inst.GetChild(name)
dst = append(dst, child)
}
return dst
}