-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
92 lines (85 loc) · 1.87 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
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
package main
import (
"strings"
)
func splitPath(name string) []string {
_names := strings.Split(name, "/")
names := []string{}
for _, _name := range _names {
if _name != "" {
names = append(names, _name)
}
}
return names
}
func handleMinioError(err error) error {
return err
}
func listChildDummyDirs(dummyDirs []string, bucket string, path string) []string {
key := bucket
if path != "" {
key += "/" + path
}
dirs := map[string]struct{}{}
for _, dummyDir := range dummyDirs {
if strings.HasPrefix(dummyDir, key+"/") {
tmp := strings.Split(strings.TrimPrefix(dummyDir, key+"/"), "/")
if len(tmp) == 1 {
dirs[tmp[0]] = struct{}{}
}
}
}
_dirs := []string{}
for dir := range dirs {
_dirs = append(_dirs, dir)
}
return _dirs
}
func isDummyDir(dummyDirs []string, bucket string, path string) bool {
key := bucket
if path != "" {
key += "/" + path
}
for _, dummyDir := range dummyDirs {
if dummyDir == key {
return true
}
}
return false
}
func deleteDummyDir(dummyDirs []string, bucket string, path string) []string {
key := bucket
if path != "" {
key += "/" + path
}
_dummyDirs := []string{}
for _, dummyDir := range dummyDirs {
if !strings.HasPrefix(dummyDir, key) {
_dummyDirs = append(_dummyDirs, dummyDir)
}
}
return _dummyDirs
}
func renameDummyDir(dummyDirs []string, bucket string, path string, newBucket string, newPath string) ([]string, bool) {
key := bucket
if path != "" {
key += "/" + path
}
newKey := newBucket
if newPath != "" {
newKey += "/" + newPath
}
_dummyDirs := []string{}
renameDummy := false
for _, dummyDir := range dummyDirs {
if strings.HasPrefix(dummyDir, key) {
if dummyDir == key {
renameDummy = true
}
_dummyDirs = append(_dummyDirs, strings.Replace(dummyDir, key, newKey, 1))
} else {
_dummyDirs = append(_dummyDirs, dummyDir)
}
}
return _dummyDirs, renameDummy
}