-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathpath.go
58 lines (50 loc) · 1 KB
/
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
package core
import (
"path/filepath"
"strings"
)
type Path struct {
origin string
fsType VFSType
bucket string
base string
}
func newPath(path string, fsType VFSType) Path {
p := Path{
origin: path,
fsType: fsType,
}
p.parse()
return p
}
// Bucket returns bucket name
func (p Path) Bucket() string {
return p.bucket
}
// Base returns base path
func (p Path) Base() string {
return p.base
}
// String return the origin path
func (p Path) String() string {
return p.origin
}
func (p *Path) parse() {
// maybe the remote os is different from the current os, force convert remote path to slash
if p.fsType != MinIO {
p.origin = filepath.ToSlash(filepath.Clean(p.origin))
}
p.base = p.origin
if p.fsType == MinIO {
// protocol => bucket:path
// example => mybucket:/workspace
if strings.Contains(p.origin, ":") && !strings.HasPrefix(p.origin, "/") {
list := strings.Split(p.origin, ":")
p.bucket = list[0]
p.base = list[1]
} else {
p.bucket = p.origin
p.base = ""
}
}
}