@@ -24,15 +24,24 @@ func databaseName(c schemeClient) string {
2424}
2525
2626func IsDirectoryExists (ctx context.Context , c schemeClient , directory string ) (exists bool , _ error ) {
27+ if ! strings .HasPrefix (directory , databaseName (c )) {
28+ return false , xerrors .WithStackTrace (fmt .Errorf (
29+ "path '%s' must be inside database '%s'" ,
30+ directory , databaseName (c ),
31+ ))
32+ }
33+ if directory == databaseName (c ) {
34+ return true , nil
35+ }
2736 parentDirectory , childDirectory := path .Split (directory )
2837 parentDirectory = strings .TrimRight (parentDirectory , "/" )
29- if parentDirectory != databaseName (c ) {
30- if exists , err := IsDirectoryExists (ctx , c , parentDirectory ); err != nil {
31- return false , xerrors .WithStackTrace (err )
32- } else if ! exists {
33- return false , nil
34- }
38+
39+ if exists , err := IsDirectoryExists (ctx , c , parentDirectory ); err != nil {
40+ return false , xerrors .WithStackTrace (err )
41+ } else if ! exists {
42+ return false , nil
3543 }
44+
3645 d , err := c .ListDirectory (ctx , parentDirectory )
3746 if err != nil {
3847 return false , xerrors .WithStackTrace (err )
@@ -43,7 +52,7 @@ func IsDirectoryExists(ctx context.Context, c schemeClient, directory string) (e
4352 }
4453 if e .Type != scheme .EntryDirectory {
4554 return false , xerrors .WithStackTrace (fmt .Errorf (
46- "entry '%s' in path '%s' is not a direectory : %s" ,
55+ "entry '%s' in path '%s' is not a directory : %s" ,
4756 childDirectory , parentDirectory , e .Type .String (),
4857 ))
4958 }
0 commit comments