Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit a6ce6f9

Browse files
author
Joonas Koivunen
committed
doc: minor docs and fmt
1 parent 38a2cd7 commit a6ce6f9

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

unixfs/benches/ingest-tar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn ingest_tar(bytes: &[u8]) {
3131
let mut tree = BufferingTreeBuilder::new(opts);
3232

3333
for entry in entries {
34-
let mut entry = entry.except("assuming good tar");
34+
let mut entry = entry.expect("assuming good tar");
3535

3636
let path = std::str::from_utf8(&*entry.path_bytes())
3737
.unwrap()

unixfs/src/dir/builder/iter.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub struct PostOrderIterator {
3131
/// to have only `Some` values.
3232
type Leaves = Vec<Option<NamedLeaf>>;
3333

34+
/// The nodes in the visit. We need to do a post-order visit, which starts from a single
35+
/// `DescentRoot`, followed by N `Descents` where N is the deepest directory in the tree. On each
36+
/// descent, we'll need to first schedule a `Post` (or `PostRoot`) followed the immediate children
37+
/// of the node. Directories are rendered when all of their direct and indirect descendants have
38+
/// been serialized into NamedLeafs.
3439
#[derive(Debug)]
3540
enum Visited {
3641
// handle root differently not to infect with the Option<String> and Option<usize>
@@ -39,13 +44,16 @@ enum Visited {
3944
node: DirBuilder,
4045
name: String,
4146
depth: usize,
47+
/// The index in the parents `Leaves` accessible through `PostOrderIterator::persisted_cids`.
4248
index: usize,
4349
},
4450
Post {
4551
parent_id: u64,
4652
depth: usize,
4753
name: String,
4854
index: usize,
55+
/// Leaves will be stored directly in this field when there are no DirBuilder descendants,
56+
/// in the `PostOrderIterator::persisted_cids` otherwise.
4957
leaves: LeafStorage,
5058
},
5159
PostRoot {
@@ -168,15 +176,10 @@ impl PostOrderIterator {
168176
match visited {
169177
Visited::DescentRoot(node) => {
170178
let children = &mut self.reused_children;
171-
172179
let leaves = partition_children_leaves(depth, node.nodes.into_iter(), children);
173-
174-
// initial idea was to validate something with
175-
176180
let any_children = !children.is_empty();
177181

178182
let leaves = if any_children {
179-
// we only need to put the leaves in there in the case of wrapping
180183
self.persisted_cids.insert(node.id, leaves);
181184
LeafStorage::from(node.id)
182185
} else {
@@ -193,14 +196,9 @@ impl PostOrderIterator {
193196
index,
194197
} => {
195198
let children = &mut self.reused_children;
196-
197199
let leaves = partition_children_leaves(depth, node.nodes.into_iter(), children);
198-
199200
let any_children = !children.is_empty();
200-
201-
// this would be none for only the single first node, however we know already
202-
// this is not the branch DescentRoot
203-
let parent_id = node.parent_id.expect("this is not root");
201+
let parent_id = node.parent_id.expect("only roots parent_id is None");
204202

205203
let leaves = if any_children {
206204
self.persisted_cids.insert(node.id, leaves);
@@ -227,7 +225,6 @@ impl PostOrderIterator {
227225
..
228226
} => {
229227
let leaves = leaves.into_inner(&mut self.persisted_cids);
230-
231228
let buffer = &mut self.block_buffer;
232229

233230
let leaf = match Self::render_directory(
@@ -450,7 +447,7 @@ impl LeafStorage {
450447
Stashed(id) => stash
451448
.remove(&id)
452449
.ok_or(id)
453-
.expect("could not find stashed leaves"),
450+
.expect("leaves are either stashed or direct, must able to find with id"),
454451
}
455452
}
456453
}

0 commit comments

Comments
 (0)