@@ -117,6 +117,7 @@ impl MemStore {
117117 state : State {
118118 data : HashMap :: new ( ) ,
119119 tags : BTreeMap :: new ( ) ,
120+ empty_hash : BaoFileHandle :: new_partial ( Hash :: EMPTY ) ,
120121 } ,
121122 options : Arc :: new ( Options :: default ( ) ) ,
122123 temp_tags : Default :: default ( ) ,
@@ -189,15 +190,24 @@ impl Actor {
189190 self . spawn ( import_path ( cmd) ) ;
190191 }
191192 Command :: ExportBao ( ExportBaoMsg {
192- inner : ExportBaoRequest { hash, ranges } ,
193+ inner :
194+ ExportBaoRequest {
195+ hash,
196+ ranges,
197+ create_if_missing,
198+ } ,
193199 tx,
194200 ..
195201 } ) => {
196- let entry = self . state . data . get ( & hash) . cloned ( ) ;
202+ let entry = if create_if_missing {
203+ Some ( self . get_or_create_entry ( hash) )
204+ } else {
205+ self . get ( & hash)
206+ } ;
197207 self . spawn ( export_bao ( entry, ranges, tx) )
198208 }
199209 Command :: ExportPath ( cmd) => {
200- let entry = self . state . data . get ( & cmd. hash ) . cloned ( ) ;
210+ let entry = self . get ( & cmd. hash ) ;
201211 self . spawn ( export_path ( entry, cmd) ) ;
202212 }
203213 Command :: DeleteTags ( cmd) => {
@@ -329,7 +339,7 @@ impl Actor {
329339 tx,
330340 ..
331341 } = cmd;
332- let res = match self . state . data . get ( & hash) {
342+ let res = match self . get ( & hash) {
333343 None => api:: blobs:: BlobStatus :: NotFound ,
334344 Some ( x) => {
335345 let bitfield = x. 0 . state . borrow ( ) . bitfield ( ) ;
@@ -371,7 +381,7 @@ impl Actor {
371381 cmd. tx . send ( Ok ( ( ) ) ) . await . ok ( ) ;
372382 }
373383 Command :: ExportRanges ( cmd) => {
374- let entry = self . state . data . get ( & cmd. hash ) . cloned ( ) ;
384+ let entry = self . get ( & cmd. hash ) ;
375385 self . spawn ( export_ranges ( cmd, entry) ) ;
376386 }
377387 Command :: SyncDb ( SyncDbMsg { tx, .. } ) => {
@@ -384,12 +394,24 @@ impl Actor {
384394 None
385395 }
386396
397+ fn get ( & mut self , hash : & Hash ) -> Option < BaoFileHandle > {
398+ if * hash == Hash :: EMPTY {
399+ Some ( self . state . empty_hash . clone ( ) )
400+ } else {
401+ self . state . data . get ( hash) . cloned ( )
402+ }
403+ }
404+
387405 fn get_or_create_entry ( & mut self , hash : Hash ) -> BaoFileHandle {
388- self . state
389- . data
390- . entry ( hash)
391- . or_insert_with ( || BaoFileHandle :: new_partial ( hash) )
392- . clone ( )
406+ if hash == Hash :: EMPTY {
407+ self . state . empty_hash . clone ( )
408+ } else {
409+ self . state
410+ . data
411+ . entry ( hash)
412+ . or_insert_with ( || BaoFileHandle :: new_partial ( hash) )
413+ . clone ( )
414+ }
393415 }
394416
395417 async fn create_temp_tag ( & mut self , cmd : CreateTempTagMsg ) {
@@ -839,6 +861,7 @@ impl Outboard for OutboardReader {
839861struct State {
840862 data : HashMap < Hash , BaoFileHandle > ,
841863 tags : BTreeMap < Tag , HashAndFormat > ,
864+ empty_hash : BaoFileHandle ,
842865}
843866
844867#[ derive( Debug , derive_more:: From ) ]
0 commit comments