Skip to content

Commit e6e765a

Browse files
authored
Merge pull request #699 from ydb-platform/removerecursive_fix
fix: sugar.RemoveRecursive do nothing if path is database root
2 parents 278fab9 + 1a8b5b7 commit e6e765a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sugar/path.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
const (
16-
sysTable = ".sys"
16+
sysDirectory = ".sys"
1717
)
1818

1919
type dbName interface {
@@ -49,9 +49,9 @@ type dbFoRemoveRecursive interface {
4949
// MakeRecursive method equal bash command `mkdir -p ~/path/to/create`
5050
// where `~` - is a root of database
5151
func MakeRecursive(ctx context.Context, db dbForMakeRecursive, pathToCreate string) error {
52-
if strings.HasPrefix(pathToCreate, sysTable+"/") {
52+
if strings.HasPrefix(pathToCreate, sysDirectory+"/") {
5353
return xerrors.WithStackTrace(
54-
fmt.Errorf("making directory %q inside system path %q not supported", pathToCreate, sysTable),
54+
fmt.Errorf("making directory %q inside system path %q not supported", pathToCreate, sysDirectory),
5555
)
5656
}
5757

@@ -90,7 +90,7 @@ func MakeRecursive(ctx context.Context, db dbForMakeRecursive, pathToCreate stri
9090
// RemoveRecursive method equal bash command `rm -rf ~/path/to/remove`
9191
// where `~` - is a root of database
9292
func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove string) error {
93-
fullSysTablePath := path.Join(db.Name(), sysTable)
93+
fullSysTablePath := path.Join(db.Name(), sysDirectory)
9494
var rmPath func(int, string) error
9595
rmPath = func(i int, p string) error {
9696
if exists, err := IsDirectoryExists(ctx, db.Scheme(), p); err != nil {
@@ -108,7 +108,7 @@ func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove s
108108
)
109109
}
110110

111-
if entry.Type != scheme.EntryDirectory {
111+
if entry.Type != scheme.EntryDirectory && entry.Type != scheme.EntryDatabase {
112112
return nil
113113
}
114114

@@ -157,6 +157,10 @@ func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove s
157157
}
158158
}
159159

160+
if entry.Type != scheme.EntryDirectory {
161+
return nil
162+
}
163+
160164
err = db.Scheme().RemoveDirectory(ctx, p)
161165
if err != nil {
162166
return xerrors.WithStackTrace(

0 commit comments

Comments
 (0)