Skip to content

Commit dd59017

Browse files
committed
fix: make other tests pass again
1 parent 004acc0 commit dd59017

File tree

6 files changed

+54
-16
lines changed

6 files changed

+54
-16
lines changed

src/api/blobs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl Blobs {
302302
ExportBaoRequest {
303303
hash: hash.into(),
304304
ranges: ranges.into(),
305+
create_if_missing: false,
305306
},
306307
32,
307308
)

src/api/proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub struct ObserveRequest {
222222
pub struct ExportBaoRequest {
223223
pub hash: Hash,
224224
pub ranges: ChunkRanges,
225+
pub create_if_missing: bool,
225226
}
226227

227228
/// Export the given ranges as chunkks, without validation.

src/api/remote.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use nested_enum_utils::common_fields;
1010
use ref_cast::RefCast;
1111
use snafu::{Backtrace, IntoError, Snafu};
1212

13-
use super::blobs::Bitfield;
13+
use super::blobs::{Bitfield, ExportBaoOptions};
1414
use crate::{
1515
api::{blobs::WriteProgress, ApiClient},
1616
get::{fsm::DecodeError, BadRequestSnafu, GetError, GetResult, LocalFailureSnafu, Stats},
@@ -159,7 +159,7 @@ impl PushProgress {
159159

160160
async fn just_result<S, R>(stream: S) -> Option<R>
161161
where
162-
S: Stream,
162+
S: Stream<Item: std::fmt::Debug>,
163163
R: TryFrom<S::Item>,
164164
{
165165
tokio::pin!(stream);
@@ -417,7 +417,12 @@ impl Remote {
417417
let root = request.hash;
418418
let bitfield = self.store().observe(root).await?;
419419
let children = if !request.ranges.is_blob() {
420-
let bao = self.store().export_bao(root, bitfield.ranges.clone());
420+
let opts = ExportBaoOptions {
421+
hash: root,
422+
ranges: bitfield.ranges.clone(),
423+
create_if_missing: true,
424+
};
425+
let bao = self.store().export_bao_with_opts(opts, 32);
421426
let mut by_index = BTreeMap::new();
422427
let mut stream = bao.hashes_with_index();
423428
while let Some(item) = stream.next().await {

src/store/fs.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ impl HashContext {
305305
Ok(())
306306
}
307307

308+
pub async fn get_maybe_create(&self, hash: Hash, create: bool) -> api::Result<BaoFileHandle> {
309+
if create {
310+
self.get_or_create(hash).await
311+
} else {
312+
self.get(hash).await
313+
}
314+
}
315+
308316
pub async fn get(&self, hash: Hash) -> api::Result<BaoFileHandle> {
309317
if hash == Hash::EMPTY {
310318
return Ok(self.ctx.empty.clone());
@@ -1020,7 +1028,7 @@ async fn export_ranges_impl(
10201028

10211029
#[instrument(skip_all, fields(hash = %cmd.hash_short()))]
10221030
async fn export_bao(mut cmd: ExportBaoMsg, ctx: HashContext) {
1023-
match ctx.get(cmd.hash).await {
1031+
match ctx.get_maybe_create(cmd.hash, cmd.create_if_missing).await {
10241032
Ok(handle) => {
10251033
if let Err(cause) = export_bao_impl(cmd.inner, &mut cmd.tx, handle).await {
10261034
cmd.tx
@@ -1044,7 +1052,7 @@ async fn export_bao_impl(
10441052
tx: &mut mpsc::Sender<EncodedItem>,
10451053
handle: BaoFileHandle,
10461054
) -> anyhow::Result<()> {
1047-
let ExportBaoRequest { ranges, hash } = cmd;
1055+
let ExportBaoRequest { ranges, hash, .. } = cmd;
10481056
debug_assert!(handle.hash() == hash, "hash mismatch");
10491057
let outboard = handle.outboard()?;
10501058
let size = outboard.tree.size();

src/store/mem.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
839861
struct State {
840862
data: HashMap<Hash, BaoFileHandle>,
841863
tags: BTreeMap<Tag, HashAndFormat>,
864+
empty_hash: BaoFileHandle,
842865
}
843866

844867
#[derive(Debug, derive_more::From)]

src/store/readonly_mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Actor {
117117
});
118118
}
119119
Command::ExportBao(ExportBaoMsg {
120-
inner: ExportBaoRequest { hash, ranges },
120+
inner: ExportBaoRequest { hash, ranges, .. },
121121
tx,
122122
..
123123
}) => {

0 commit comments

Comments
 (0)