mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Merge pull request #526 from rustic-rs/node-content
Avoid panic when content field is missing
This commit is contained in:
commit
43fe7dc80b
@ -161,8 +161,8 @@ impl<BE: IndexedBackend> Parent<BE> {
|
||||
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!(
|
||||
|
||||
@ -124,10 +124,6 @@ impl Node {
|
||||
&self.meta
|
||||
}
|
||||
|
||||
pub fn content(&self) -> &Vec<Id> {
|
||||
self.content.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn subtree(&self) -> &Option<Id> {
|
||||
&self.subtree
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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 => {
|
||||
|
||||
@ -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))?;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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))?;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user