@@ -1835,7 +1835,7 @@ impl StackMachine {
1835
1835
}
1836
1836
} ;
1837
1837
1838
- let directory_subspace = match directory
1838
+ match directory
1839
1839
. create_or_open (
1840
1840
txn,
1841
1841
( * path. get ( 0 ) . unwrap ( ) . to_owned ( ) ) . to_vec ( ) ,
@@ -1844,19 +1844,17 @@ impl StackMachine {
1844
1844
)
1845
1845
. await
1846
1846
{
1847
- Ok ( s) => s,
1848
- Err ( e) => {
1849
- panic ! ( "could not call directory.create: {:?}" , e) ;
1847
+ Ok ( directory_subspace) => {
1848
+ debug ! (
1849
+ "pushing created_or_opened {:?} at index {}" ,
1850
+ & directory_subspace,
1851
+ self . directory_stack. len( )
1852
+ ) ;
1853
+ self . directory_stack
1854
+ . push ( DirectoryStackItem :: DirectorySubspace ( directory_subspace) ) ;
1850
1855
}
1856
+ Err ( e) => self . push_directory_err ( & instr. code , number, e) ,
1851
1857
} ;
1852
-
1853
- debug ! (
1854
- "pushing created_or_opened {:?} at index {}" ,
1855
- & directory_subspace,
1856
- self . directory_stack. len( )
1857
- ) ;
1858
- self . directory_stack
1859
- . push ( DirectoryStackItem :: DirectorySubspace ( directory_subspace) ) ;
1860
1858
}
1861
1859
1862
1860
// Pop the top item off the stack as [index]. Set the current directory list
@@ -2003,10 +2001,12 @@ impl StackMachine {
2003
2001
} ;
2004
2002
2005
2003
let paths = paths. get ( 0 ) . expect ( "could not retrieve a path" ) ;
2006
- directory
2007
- . remove ( txn, paths. to_owned ( ) )
2008
- . await
2009
- . expect ( "could not delete" ) ;
2004
+ match directory. remove ( txn, paths. to_owned ( ) ) . await {
2005
+ Ok ( _) => { }
2006
+ Err ( e) => {
2007
+ self . push_directory_err ( & instr. code , number, e) ;
2008
+ }
2009
+ }
2010
2010
}
2011
2011
2012
2012
// Use the current directory for this operation.
@@ -2177,13 +2177,36 @@ impl StackMachine {
2177
2177
//
2178
2178
// Pop 1 item off the stack as [key]. Check if the current directory contains
2179
2179
// the specified key. Push 1 if it does and 0 if it doesn't.
2180
- DirectoryContains => unimplemented ! ( ) ,
2180
+ DirectoryContains => {
2181
+ let raw_prefix = self . pop_bytes ( ) . await ;
2182
+ let b = self
2183
+ . get_current_directory_subspace ( )
2184
+ . unwrap ( )
2185
+ . subspace ( & ( ) )
2186
+ . is_start_of ( & raw_prefix) ;
2187
+ self . push ( number, Element :: Bool ( b) ) ;
2188
+ }
2181
2189
2182
2190
// Use the current directory for this operation.
2183
2191
//
2184
2192
// Pop 1 tuple off the stack as [tuple]. Open the subspace of the current
2185
2193
// directory specified by tuple and push it onto the directory list.
2186
- DirectoryOpenSubspace => unimplemented ! ( ) ,
2194
+ DirectoryOpenSubspace => {
2195
+ debug ! ( "directory_open_subspace stack: {:?}" , self . stack) ;
2196
+ let n: usize = self . pop_usize ( ) . await ;
2197
+ debug ! ( "DirectoryRange {}" , n) ;
2198
+ let mut buf = Vec :: new ( ) ;
2199
+ for _ in 0 ..n {
2200
+ let element: Element = self . pop_element ( ) . await ;
2201
+ debug ! ( " - {:?}" , element) ;
2202
+ buf. push ( element) ;
2203
+ }
2204
+
2205
+ let tuple = Element :: Tuple ( buf) ;
2206
+ self . directory_stack . push ( DirectoryStackItem :: Subspace (
2207
+ self . subspace_with_current ( & tuple) . unwrap ( ) ,
2208
+ ) ) ;
2209
+ }
2187
2210
2188
2211
// Use the current directory for this operation.
2189
2212
//
@@ -2269,7 +2292,26 @@ impl StackMachine {
2269
2292
// subspace and store the result as [prefix]. Throw an error if the popped
2270
2293
// array does not start with prefix. Otherwise, remove the prefix from the
2271
2294
// popped array and push the result onto the stack.
2272
- DirectoryStripPrefix => unimplemented ! ( ) ,
2295
+ DirectoryStripPrefix => {
2296
+ debug ! ( "directory_strip_prefix stack: {:?}" , self . stack) ;
2297
+ let raw_prefix = self . pop_bytes ( ) . await ;
2298
+ let subspace_bytes_length =
2299
+ self . get_current_directory_subspace ( ) . unwrap ( ) . bytes ( ) . len ( ) ;
2300
+ if raw_prefix. len ( ) != subspace_bytes_length {
2301
+ self . push_directory_err (
2302
+ & instr. code ,
2303
+ number,
2304
+ DirectoryError :: Version ( String :: from (
2305
+ "String does not start with raw prefix" ,
2306
+ ) ) ,
2307
+ ) ;
2308
+ } else {
2309
+ self . push (
2310
+ number,
2311
+ Element :: Bytes ( Bytes :: from ( raw_prefix[ subspace_bytes_length..] . to_owned ( ) ) ) ,
2312
+ ) ;
2313
+ }
2314
+ }
2273
2315
}
2274
2316
2275
2317
if is_db && pending {
0 commit comments