@@ -111,7 +111,10 @@ impl Default for DirectoryLayer {
111
111
}
112
112
113
113
impl DirectoryLayer {
114
- /// Creates or opens the directory located at path(creating parent directories, if necessary).
114
+ /// CreateOrOpen opens the directory specified by path (relative to this
115
+ /// Directory), and returns the directory and its contents as a
116
+ /// Subspace. If the directory does not exist, it is created
117
+ /// (creating parent directories if necessary).
115
118
pub async fn create_or_open (
116
119
& self ,
117
120
txn : & Transaction ,
@@ -121,14 +124,19 @@ impl DirectoryLayer {
121
124
. await
122
125
}
123
126
124
- /// Creates a directory located at path (creating parent directories if necessary).
127
+ /// Create creates a directory specified by path (relative to this
128
+ /// Directory), and returns the directory and its contents as a
129
+ /// Subspace (or ErrDirAlreadyExists if the directory already exists).
125
130
pub async fn create ( & self , txn : & Transaction , paths : Vec < String > ) -> Option < DirectoryError > {
126
131
self . create_or_open_internal ( txn, paths, vec ! [ ] , true , false )
127
132
. await
128
133
. err ( )
129
134
}
130
135
131
- /// Opens the directory located at path.
136
+ /// Open opens the directory specified by path (relative to this Directory),
137
+ /// and returns the directory and its contents as a Subspace (or Err(DirNotExists)
138
+ /// error if the directory does not exist, or ErrParentDirDoesNotExist if one of the parent
139
+ /// directories in the path does not exist).
132
140
pub async fn open (
133
141
& self ,
134
142
txn : & Transaction ,
@@ -138,7 +146,46 @@ impl DirectoryLayer {
138
146
. await
139
147
}
140
148
141
- /// list all sub-directory contained in the path
149
+ /// Exists returns true if the directory at path (relative to the default root directory) exists, and false otherwise.
150
+ pub async fn exists (
151
+ & self ,
152
+ trx : & Transaction ,
153
+ paths : Vec < String > ,
154
+ ) -> Result < bool , DirectoryError > {
155
+ let nodes = self . find_nodes ( trx, paths. to_owned ( ) ) . await ?;
156
+
157
+ match nodes. last ( ) {
158
+ None => Err ( DirectoryError :: DirNotExists ) ,
159
+ Some ( _) => Ok ( true ) ,
160
+ }
161
+ }
162
+
163
+ /// Move moves the directory at oldPath to newPath (both relative to this
164
+ /// Directory), and returns the directory (at its new location) and its
165
+ /// contents as a Subspace. Move will return an error if a directory
166
+ /// does not exist at oldPath, a directory already exists at newPath, or the
167
+ /// parent directory of newPath does not exist.
168
+ pub async fn move_to (
169
+ & self ,
170
+ trx : & Transaction ,
171
+ old_path : Vec < String > ,
172
+ new_path : Vec < String > ,
173
+ ) -> Result < bool , DirectoryError > {
174
+ unimplemented ! ( "move is not supported yet" )
175
+ }
176
+
177
+ /// Exists returns true if the directory at path (relative to this Directory)
178
+ /// exists, and false otherwise.
179
+ pub async fn remove (
180
+ & self ,
181
+ trx : & Transaction ,
182
+ path : Vec < String > ,
183
+ ) -> Result < bool , DirectoryError > {
184
+ unimplemented ! ( "move is not supported yet" )
185
+ }
186
+
187
+ /// List returns the names of the immediate subdirectories of the default root directory as a slice of strings.
188
+ /// Each string is the name of the last component of a subdirectory's path.
142
189
pub async fn list (
143
190
& self ,
144
191
trx : & Transaction ,
0 commit comments