diff --git a/src/archiver/parent.rs b/src/archiver/parent.rs index d025f2e..2a7e8fd 100644 --- a/src/archiver/parent.rs +++ b/src/archiver/parent.rs @@ -161,8 +161,8 @@ impl Parent { let parent = self.is_parent(&node, &node.name()); let parent = match parent { ParentResult::Matched(p_node) => { - if p_node.content().iter().all(|id| be.has_data(id)) { - node.set_content(p_node.content().to_vec()); + if p_node.content.iter().flatten().all(|id| be.has_data(id)) { + node.set_content(p_node.content.iter().flatten().copied().collect()); ParentResult::Matched(()) } else { warn!( diff --git a/src/backend/node.rs b/src/backend/node.rs index 602f92b..12f78a6 100644 --- a/src/backend/node.rs +++ b/src/backend/node.rs @@ -124,10 +124,6 @@ impl Node { &self.meta } - pub fn content(&self) -> &Vec { - self.content.as_ref().unwrap() - } - pub fn subtree(&self) -> &Option { &self.subtree } diff --git a/src/commands/check.rs b/src/commands/check.rs index 44622e3..dc90502 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -291,21 +291,26 @@ fn check_snapshots(index: &impl IndexedBackend) -> Result<()> { let (path, tree) = item; for node in tree.nodes() { match node.node_type() { - NodeType::File => { - for (i, id) in node.content().iter().enumerate() { - if id.is_null() { - error!("file {:?} blob {} has null ID", path.join(node.name()), i); - } + NodeType::File => match &node.content { + Some(content) => { + for (i, id) in content.iter().enumerate() { + if id.is_null() { + error!("file {:?} blob {} has null ID", path.join(node.name()), i); + } - if !index.has_data(id) { - error!( - "file {:?} blob {} is missing in index", - path.join(node.name()), - id - ); + if !index.has_data(id) { + error!( + "file {:?} blob {} is missing in index", + path.join(node.name()), + id + ); + } } } - } + None => { + error!("file {:?} doesn't have a content", path.join(node.name())); + } + }, NodeType::Dir => { match node.subtree() { diff --git a/src/commands/copy.rs b/src/commands/copy.rs index bf5f714..2d98413 100644 --- a/src/commands/copy.rs +++ b/src/commands/copy.rs @@ -127,14 +127,17 @@ fn copy( tree.nodes().par_iter().try_for_each(|node| { match node.node_type() { NodeType::File => { - node.content().par_iter().try_for_each(|id| -> Result<_> { - trace!("copy data blob {id}"); - if !index_dest.has_data(id) { - let data = index.get_data(id).unwrap().read_data(index.be())?; - data_packer.add(&data, id)?; - } - Ok(()) - })?; + node.content + .par_iter() + .flatten() + .try_for_each(|id| -> Result<_> { + trace!("copy data blob {id}"); + if !index_dest.has_data(id) { + let data = index.get_data(id).unwrap().read_data(index.be())?; + data_packer.add(&data, id)?; + } + Ok(()) + })?; } NodeType::Dir => { diff --git a/src/commands/diff.rs b/src/commands/diff.rs index 801fc78..32fc41e 100644 --- a/src/commands/diff.rs +++ b/src/commands/diff.rs @@ -65,7 +65,7 @@ pub(super) fn execute( NodeStreamer::new(index.clone(), &node1)?, NodeStreamer::new(index, &node2)?, opts.no_content, - |_path, node1, node2| Ok(node1.content() == node2.content()), + |_path, node1, node2| Ok(node1.content == node2.content), opts.metadata, ) } @@ -133,7 +133,7 @@ fn identical_content_local( None => return Ok(false), }; - for id in node.content() { + for id in node.content.iter().flatten() { let ie = index .get_data(id) .ok_or_else(|| anyhow!("did not find id {} in index", id))?; diff --git a/src/commands/prune.rs b/src/commands/prune.rs index 7d07086..5bf5378 100644 --- a/src/commands/prune.rs +++ b/src/commands/prune.rs @@ -1109,7 +1109,9 @@ fn find_used_blobs( let (_, tree) = item; for node in tree.nodes() { match node.node_type() { - NodeType::File => ids.extend(node.content().iter().map(|id| (*id, 0))), + NodeType::File => { + ids.extend(node.content.iter().flatten().map(|id| (*id, 0))); + } NodeType::Dir => { ids.insert(node.subtree().unwrap(), 0); } diff --git a/src/commands/restore.rs b/src/commands/restore.rs index d9b7b2f..7e4421e 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -548,7 +548,7 @@ impl FileInfos { self.names.push(name); let mut file_pos = 0; let mut has_unmatched = false; - for id in file.content().iter() { + for id in file.content.iter().flatten() { let ie = index .get_data(id) .ok_or_else(|| anyhow!("did not find id {} in index", id))?;