@@ -12,19 +12,28 @@ import (
12
12
"github.com/ydb-platform/ydb-go-sdk/v3/table"
13
13
)
14
14
15
- // MakePath creates path inside database
16
- func MakePath (ctx context.Context , db ydb.Connection , path string ) error {
17
- for i := len (db .Name ()) + 1 ; i < len (path ); i ++ {
18
- x := strings .IndexByte (path [i :], '/' )
15
+ const (
16
+ sysTable = ".sys"
17
+ )
18
+
19
+ // MakeRecursive creates path inside database
20
+ func MakeRecursive (ctx context.Context , db ydb.Connection , folder string ) error {
21
+ folder = path .Join (db .Name (), folder )
22
+ for i := len (db .Name ()) + 1 ; i < len (folder ); i ++ {
23
+ x := strings .IndexByte (folder [i :], '/' )
19
24
if x == - 1 {
20
- x = len (path [i :]) - 1
25
+ x = len (folder [i :]) - 1
21
26
}
22
27
i += x
23
- sub := path [:i + 1 ]
28
+ sub := folder [:i + 1 ]
24
29
info , err := db .Scheme ().DescribePath (ctx , sub )
25
30
var opErr * errors.OpError
26
31
if errors .As (err , & opErr ) && opErr .Reason == errors .StatusSchemeError {
27
32
err = db .Scheme ().MakeDirectory (ctx , sub )
33
+ if err != nil {
34
+ return err
35
+ }
36
+ info , err = db .Scheme ().DescribePath (ctx , sub )
28
37
}
29
38
if err != nil {
30
39
return err
@@ -41,19 +50,15 @@ func MakePath(ctx context.Context, db ydb.Connection, path string) error {
41
50
)
42
51
}
43
52
}
44
-
45
53
return nil
46
54
}
47
55
48
- // RmPath remove selected directory or table names in database.
56
+ // RemoveRecursive remove selected directory or table names in database.
49
57
// All database entities in prefix path will remove if names list is empty.
50
58
// Empty prefix means than use root of database.
51
- // RmPath method equal bash command `rm -rf ./pathToRemove/{name1,name2,name3}`
52
- func RmPath (ctx context.Context , db ydb.Connection , pathToRemove string , names ... string ) error {
53
- filter := make (map [string ]struct {}, len (names ))
54
- for _ , n := range names {
55
- filter [n ] = struct {}{}
56
- }
59
+ // RemoveRecursive method equal bash command `rm -rf ./path/to/remove`
60
+ func RemoveRecursive (ctx context.Context , db ydb.Connection , pathToRemove string ) error {
61
+ fullSysTablePath := path .Join (db .Name (), sysTable )
57
62
var list func (int , string ) error
58
63
list = func (i int , p string ) error {
59
64
dir , err := db .Scheme ().ListDirectory (ctx , p )
@@ -65,10 +70,10 @@ func RmPath(ctx context.Context, db ydb.Connection, pathToRemove string, names .
65
70
return err
66
71
}
67
72
for _ , child := range dir .Children {
68
- if _ , has := filter [child .Name ]; ! has {
73
+ pt := path .Join (p , child .Name )
74
+ if pt == fullSysTablePath {
69
75
continue
70
76
}
71
- pt := path .Join (p , child .Name )
72
77
switch child .Type {
73
78
case scheme .EntryDirectory :
74
79
if err = list (i + 1 , pt ); err != nil {
0 commit comments