@@ -1835,7 +1835,7 @@ impl StackMachine {
18351835 }
18361836 } ;
18371837
1838- let directory_subspace = match directory
1838+ match directory
18391839 . create_or_open (
18401840 txn,
18411841 ( * path. get ( 0 ) . unwrap ( ) . to_owned ( ) ) . to_vec ( ) ,
@@ -1844,19 +1844,17 @@ impl StackMachine {
18441844 )
18451845 . await
18461846 {
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) ) ;
18501855 }
1856+ Err ( e) => self . push_directory_err ( & instr. code , number, e) ,
18511857 } ;
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) ) ;
18601858 }
18611859
18621860 // Pop the top item off the stack as [index]. Set the current directory list
@@ -2003,10 +2001,12 @@ impl StackMachine {
20032001 } ;
20042002
20052003 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+ }
20102010 }
20112011
20122012 // Use the current directory for this operation.
@@ -2177,13 +2177,36 @@ impl StackMachine {
21772177 //
21782178 // Pop 1 item off the stack as [key]. Check if the current directory contains
21792179 // 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+ }
21812189
21822190 // Use the current directory for this operation.
21832191 //
21842192 // Pop 1 tuple off the stack as [tuple]. Open the subspace of the current
21852193 // 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+ }
21872210
21882211 // Use the current directory for this operation.
21892212 //
@@ -2269,7 +2292,26 @@ impl StackMachine {
22692292 // subspace and store the result as [prefix]. Throw an error if the popped
22702293 // array does not start with prefix. Otherwise, remove the prefix from the
22712294 // 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+ }
22732315 }
22742316
22752317 if is_db && pending {
0 commit comments