Skip to content

Commit 27df6da

Browse files
committed
more using HashContext instead of TaskContext
1 parent e81b1f3 commit 27df6da

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/store/fs.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl HashContext {
298298
.get_or_create(|| async {
299299
let res = self.db().get(hash).await.map_err(io::Error::other)?;
300300
let res = match res {
301-
Some(state) => open_bao_file(&hash, state, &self.global).await,
301+
Some(state) => open_bao_file(state, self).await,
302302
None => Err(io::Error::new(io::ErrorKind::NotFound, "hash not found")),
303303
};
304304
Ok((res?, ()))
@@ -318,7 +318,7 @@ impl HashContext {
318318
.get_or_create(|| async {
319319
let res = self.db().get(hash).await.map_err(io::Error::other)?;
320320
let res = match res {
321-
Some(state) => open_bao_file(&hash, state, &self.global).await,
321+
Some(state) => open_bao_file(state, self).await,
322322
None => Ok(BaoFileHandle::new_partial_mem()),
323323
};
324324
Ok((res?, ()))
@@ -331,12 +331,9 @@ impl HashContext {
331331
}
332332
}
333333

334-
async fn open_bao_file(
335-
hash: &Hash,
336-
state: EntryState<Bytes>,
337-
ctx: &TaskContext,
338-
) -> io::Result<BaoFileHandle> {
339-
let options = &ctx.options;
334+
async fn open_bao_file(state: EntryState<Bytes>, ctx: &HashContext) -> io::Result<BaoFileHandle> {
335+
let hash = &ctx.id;
336+
let options = &ctx.global.options;
340337
Ok(match state {
341338
EntryState::Complete {
342339
data_location,
@@ -368,7 +365,7 @@ async fn open_bao_file(
368365
};
369366
BaoFileHandle::new_complete(data, outboard)
370367
}
371-
EntryState::Partial { .. } => BaoFileHandle::new_partial_file(*hash, ctx).await?,
368+
EntryState::Partial { .. } => BaoFileHandle::new_partial_file(ctx).await?,
372369
})
373370
}
374371

src/store/fs/bao_file.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use super::{
3131
use crate::{
3232
api::blobs::Bitfield,
3333
store::{
34-
fs::{meta::raw_outboard_size, HashContext, TaskContext},
34+
fs::{meta::raw_outboard_size, HashContext},
3535
util::{
3636
read_checksummed_and_truncate, write_checksummed, FixedSize, MemOrFile,
3737
PartialMemStorage, DD,
@@ -577,14 +577,15 @@ impl BaoFileHandle {
577577
}
578578

579579
/// Create a new bao file handle with a partial file.
580-
pub(super) async fn new_partial_file(hash: Hash, ctx: &TaskContext) -> io::Result<Self> {
581-
let options = ctx.options.clone();
582-
let storage = PartialFileStorage::load(&hash, &options.path)?;
580+
pub(super) async fn new_partial_file(ctx: &HashContext) -> io::Result<Self> {
581+
let hash = &ctx.id;
582+
let options = ctx.global.options.clone();
583+
let storage = PartialFileStorage::load(hash, &options.path)?;
583584
let storage = if storage.bitfield.is_complete() {
584585
let size = storage.bitfield.size;
585586
let (storage, entry_state) = storage.into_complete(size, &options)?;
586587
debug!("File was reconstructed as complete");
587-
ctx.db.set(hash, entry_state).await?;
588+
ctx.global.db.set(*hash, entry_state).await?;
588589
storage.into()
589590
} else {
590591
storage.into()

0 commit comments

Comments
 (0)