@@ -23,7 +23,7 @@ use bao_tree::{
2323 mixed:: { traverse_ranges_validated, EncodedItem , ReadBytesAt } ,
2424 outboard:: PreOrderMemOutboard ,
2525 sync:: { Outboard , ReadAt , WriteAt } ,
26- BaoContentItem , Leaf ,
26+ BaoContentItem , EncodeError , Leaf ,
2727 } ,
2828 BaoTree , ChunkNum , ChunkRanges , TreeNode ,
2929} ;
@@ -193,8 +193,8 @@ impl Actor {
193193 tx,
194194 ..
195195 } ) => {
196- let entry = self . get_or_create_entry ( hash) ;
197- self . spawn ( export_bao ( entry, ranges, tx) ) ;
196+ let entry = self . state . data . get ( & hash) . cloned ( ) ;
197+ self . spawn ( export_bao ( entry, ranges, tx) )
198198 }
199199 Command :: ExportPath ( cmd) => {
200200 let entry = self . state . data . get ( & cmd. hash ) . cloned ( ) ;
@@ -371,8 +371,8 @@ impl Actor {
371371 cmd. tx . send ( Ok ( ( ) ) ) . await . ok ( ) ;
372372 }
373373 Command :: ExportRanges ( cmd) => {
374- let entry = self . get_or_create_entry ( cmd. hash ) ;
375- self . spawn ( export_ranges ( cmd, entry. clone ( ) ) ) ;
374+ let entry = self . state . data . get ( & cmd. hash ) . cloned ( ) ;
375+ self . spawn ( export_ranges ( cmd, entry) ) ;
376376 }
377377 Command :: SyncDb ( SyncDbMsg { tx, .. } ) => {
378378 tx. send ( Ok ( ( ) ) ) . await . ok ( ) ;
@@ -501,7 +501,12 @@ async fn handle_batch_impl(cmd: BatchMsg, id: Scope, scope: &Arc<TempTagScope>)
501501 Ok ( ( ) )
502502}
503503
504- async fn export_ranges ( mut cmd : ExportRangesMsg , entry : BaoFileHandle ) {
504+ async fn export_ranges ( mut cmd : ExportRangesMsg , entry : Option < BaoFileHandle > ) {
505+ let Some ( entry) = entry else {
506+ let err = io:: Error :: new ( io:: ErrorKind :: NotFound , "hash not found" ) ;
507+ cmd. tx . send ( ExportRangesItem :: Error ( err. into ( ) ) ) . await . ok ( ) ;
508+ return ;
509+ } ;
505510 if let Err ( cause) = export_ranges_impl ( cmd. inner , & mut cmd. tx , entry) . await {
506511 cmd. tx
507512 . send ( ExportRangesItem :: Error ( cause. into ( ) ) )
@@ -624,12 +629,18 @@ async fn import_bao(
624629 tx. send ( Ok ( ( ) ) ) . await . ok ( ) ;
625630}
626631
627- #[ instrument( skip_all, fields( hash = %entry . hash . fmt_short ( ) ) ) ]
632+ #[ instrument( skip_all, fields( hash = tracing :: field :: Empty ) ) ]
628633async fn export_bao (
629- entry : BaoFileHandle ,
634+ entry : Option < BaoFileHandle > ,
630635 ranges : ChunkRanges ,
631636 mut sender : mpsc:: Sender < EncodedItem > ,
632637) {
638+ let Some ( entry) = entry else {
639+ let err = EncodeError :: Io ( io:: Error :: new ( io:: ErrorKind :: NotFound , "hash not found" ) ) ;
640+ sender. send ( err. into ( ) ) . await . ok ( ) ;
641+ return ;
642+ } ;
643+ tracing:: Span :: current ( ) . record ( "hash" , tracing:: field:: display ( entry. hash ) ) ;
633644 let data = entry. data_reader ( ) ;
634645 let outboard = entry. outboard_reader ( ) ;
635646 let tx = BaoTreeSender :: new ( & mut sender) ;
0 commit comments