@@ -335,26 +335,25 @@ impl Default for BaoFileStorage {
335335impl PartialMemStorage {
336336 /// Converts this storage into a complete storage, using the given hash for
337337 /// path names and the given options for decisions about inlining.
338- fn into_complete (
339- self ,
340- hash : & Hash ,
341- ctx : & TaskContext ,
342- ) -> io:: Result < ( CompleteStorage , EntryState < Bytes > ) > {
338+ fn into_complete ( self , ctx : & HashContext ) -> io:: Result < ( CompleteStorage , EntryState < Bytes > ) > {
339+ let options = & ctx. global . options ;
340+ let hash = & ctx. id ;
343341 let size = self . current_size ( ) ;
344342 let outboard_size = raw_outboard_size ( size) ;
345- let ( data, data_location) = if ctx . options . is_inlined_data ( size) {
343+ let ( data, data_location) = if options. is_inlined_data ( size) {
346344 let data: Bytes = self . data . to_vec ( ) . into ( ) ;
347345 ( MemOrFile :: Mem ( data. clone ( ) ) , DataLocation :: Inline ( data) )
348346 } else {
349- let data_path = ctx . options . path . data_path ( hash) ;
347+ let data_path = options. path . data_path ( hash) ;
350348 let mut data_file = create_read_write ( & data_path) ?;
351349 self . data . persist ( & mut data_file) ?;
352350 (
353351 MemOrFile :: File ( FixedSize :: new ( data_file, size) ) ,
354352 DataLocation :: Owned ( size) ,
355353 )
356354 } ;
357- let ( outboard, outboard_location) = if ctx. options . is_inlined_outboard ( outboard_size) {
355+ let ( outboard, outboard_location) = if ctx. global . options . is_inlined_outboard ( outboard_size)
356+ {
358357 if outboard_size > 0 {
359358 let outboard: Bytes = self . outboard . to_vec ( ) . into ( ) ;
360359 (
@@ -365,7 +364,7 @@ impl PartialMemStorage {
365364 ( MemOrFile :: empty ( ) , OutboardLocation :: NotNeeded )
366365 }
367366 } else {
368- let outboard_path = ctx. options . path . outboard_path ( hash) ;
367+ let outboard_path = ctx. global . options . path . outboard_path ( hash) ;
369368 let mut outboard_file = create_read_write ( & outboard_path) ?;
370369 self . outboard . persist ( & mut outboard_file) ?;
371370 let outboard_location = if outboard_size == 0 {
@@ -411,10 +410,10 @@ impl BaoFileStorage {
411410 let changes = ms. bitfield . update ( bitfield) ;
412411 let new = changes. new_state ( ) ;
413412 if new. complete {
414- let ( cs, update) = ms. into_complete ( & ctx. id , & ctx . global ) ?;
413+ let ( cs, update) = ms. into_complete ( ctx) ?;
415414 ( cs. into ( ) , Some ( update) )
416415 } else {
417- let fs = ms. persist ( & ctx. global , & ctx . id ) ?;
416+ let fs = ms. persist ( ctx) ?;
418417 let update = EntryState :: Partial {
419418 size : new. validated_size ,
420419 } ;
@@ -427,7 +426,7 @@ impl BaoFileStorage {
427426 // a write at the end of a very large file.
428427 //
429428 // opt: we should check if we become complete to avoid going from mem to partial to complete
430- let mut fs = ms. persist ( & ctx. global , & ctx . id ) ?;
429+ let mut fs = ms. persist ( ctx) ?;
431430 fs. write_batch ( bitfield. size ( ) , batch) ?;
432431 let changes = fs. bitfield . update ( bitfield) ;
433432 let new = changes. new_state ( ) ;
@@ -507,20 +506,17 @@ impl BaoFileStorage {
507506pub ( crate ) struct BaoFileHandle ( Arc < watch:: Sender < BaoFileStorage > > ) ;
508507
509508impl BaoFileHandle {
510- pub fn persist ( & mut self , hash : & Hash , options : & Options ) {
509+ pub ( super ) fn persist ( & mut self , ctx : & HashContext ) {
511510 self . send_if_modified ( |guard| {
511+ let hash = & ctx. id ;
512512 if Arc :: strong_count ( & self . 0 ) > 1 {
513513 return false ;
514514 }
515515 let BaoFileStorage :: Partial ( fs) = guard. take ( ) else {
516516 return false ;
517517 } ;
518- let path = options. path . bitfield_path ( hash) ;
519- trace ! (
520- "writing bitfield for hash {} to {}" ,
521- hash,
522- path. display( )
523- ) ;
518+ let path = ctx. global . options . path . bitfield_path ( hash) ;
519+ trace ! ( "writing bitfield for hash {} to {}" , hash, path. display( ) ) ;
524520 if let Err ( cause) = fs. sync_all ( & path) {
525521 error ! (
526522 "failed to write bitfield for {} at {}: {:?}" ,
@@ -695,8 +691,7 @@ impl BaoFileHandle {
695691 trace ! ( "write_batch bitfield={:?} batch={}" , bitfield, batch. len( ) ) ;
696692 let mut res = Ok ( None ) ;
697693 self . send_if_modified ( |state| {
698- let Ok ( ( state1, update) ) = state. take ( ) . write_batch ( batch, bitfield, ctx)
699- else {
694+ let Ok ( ( state1, update) ) = state. take ( ) . write_batch ( batch, bitfield, ctx) else {
700695 res = Err ( io:: Error :: other ( "write batch failed" ) ) ;
701696 return false ;
702697 } ;
@@ -713,9 +708,10 @@ impl BaoFileHandle {
713708
714709impl PartialMemStorage {
715710 /// Persist the batch to disk.
716- fn persist ( self , ctx : & TaskContext , hash : & Hash ) -> io:: Result < PartialFileStorage > {
717- let options = & ctx. options . path ;
718- ctx. protect . protect (
711+ fn persist ( self , ctx : & HashContext ) -> io:: Result < PartialFileStorage > {
712+ let options = & ctx. global . options . path ;
713+ let hash = & ctx. id ;
714+ ctx. global . protect . protect (
719715 * hash,
720716 [
721717 BaoFilePart :: Data ,
0 commit comments