-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils.go
59 lines (45 loc) · 1.05 KB
/
utils.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
package pandorasbox
import (
"io/fs"
"os"
"strings"
"github.com/capnspacehook/pandorasbox/osfs"
"github.com/capnspacehook/pandorasbox/vfs"
)
const VFSPrefix = "vfs://"
func ConvertVFSPath(path string) (string, bool) {
if IsVFSPath(path) {
return convertVFSPath(path), true
}
return path, false
}
func convertVFSPath(path string) string {
return strings.Replace(path, VFSPrefix, "/", 1)
}
func IsVFSPath(path string) bool {
return strings.HasPrefix(path, VFSPrefix)
}
func MakeVFSPath(path string) string {
if IsVFSPath(path) {
return path
}
if len(path) > 0 && path[0] != '/' {
return VFSPrefix + path
}
return strings.Replace(path, "/", VFSPrefix, 1)
}
func IsVFS(fi fs.FileInfo) bool {
_, fivfs := fi.(*vfs.FileInfo)
return fivfs
}
func SameFile(fi1, fi2 os.FileInfo) bool {
vfsfi1, fi1vfs := fi1.(*vfs.FileInfo)
vfsfi2, fi2vfs := fi2.(*vfs.FileInfo)
if (fi1vfs && !fi2vfs) || (!fi1vfs && fi2vfs) {
return false
} else if fi1vfs && fi2vfs {
return vfs.SameFile(vfsfi1, vfsfi2)
} else {
return osfs.SameFile(fi1, fi2)
}
}