-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfilepath.go
99 lines (78 loc) · 1.71 KB
/
filepath.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
package pandorasbox
import (
stdpath "path"
"path/filepath"
)
func IsAbs(path string) bool {
if _, ok := ConvertVFSPath(path); ok {
return stdpath.IsAbs(path)
}
return filepath.IsAbs(path)
}
func Clean(path string) string {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
return MakeVFSPath(stdpath.Clean(path))
}
return filepath.Clean(path)
}
func ToSlash(path string) string {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
return MakeVFSPath(filepath.ToSlash(path))
}
return filepath.ToSlash(path)
}
func FromSlash(path string) string {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
return MakeVFSPath(filepath.FromSlash(path))
}
return filepath.FromSlash(path)
}
func Split(path string) (string, string) {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
dir, file := stdpath.Split(path)
dir = MakeVFSPath(dir)
return dir, file
}
return filepath.Split(path)
}
func Join(elem ...string) string {
var isVFS bool
for i := range elem {
vfsPath, ok := ConvertVFSPath(elem[i])
if ok {
elem[i] = vfsPath
}
if i == 0 {
isVFS = ok
}
}
if isVFS {
return MakeVFSPath(stdpath.Join(elem...))
}
return filepath.Join(elem...)
}
func Ext(path string) string {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
return MakeVFSPath(stdpath.Ext(path))
}
return filepath.Ext(path)
}
func Base(path string) string {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
return MakeVFSPath(stdpath.Base(path))
}
return filepath.Base(path)
}
func Dir(path string) string {
if vfsPath, ok := ConvertVFSPath(path); ok {
path = vfsPath
return MakeVFSPath(stdpath.Dir(path))
}
return filepath.Dir(path)
}