Browse Source

fix case where the iterator recursion would blow the stack

pbs
jake 5 years ago
parent
commit
94095c21e1
  1. 26
      src/patch/patch.rs

26
src/patch/patch.rs

@ -288,7 +288,6 @@ fn does_file_need_updating(file_info: &FileInfoReply, patch_file_lookup: &HashMa
struct SendFileIterator {
done: bool,
file_iter: Box<dyn Iterator<Item = PatchTreeIterItem>>,
file_ids_to_update: HashSet<u32>,
patch_file_lookup: HashMap<u32, PatchFile>,
current_file: Option<io::BufReader<fs::File>>,
chunk_num: u32,
@ -303,9 +302,15 @@ impl SendFileIterator {
SendFileIterator {
done: false,
file_ids_to_update: file_ids_to_update,
patch_file_lookup: state.patch_file_lookup.clone(),
file_iter: Box::new(state.patch_file_tree.flatten().into_iter()),
file_iter: Box::new(state.patch_file_tree.flatten().into_iter().filter(move |file| {
match file {
PatchTreeIterItem::File(path, id) => {
file_ids_to_update.contains(&id)
},
_ => true,
}
})),
current_file: None,
chunk_num: 0,
}
@ -350,16 +355,11 @@ impl Iterator for SendFileIterator {
Some(SendPatchPacket::ChangeDirectory(ChangeDirectory::new(path.to_str().unwrap())))
},
PatchTreeIterItem::File(path, id) => {
if self.file_ids_to_update.contains(&id) {
let patch_file = self.patch_file_lookup.get(&id).unwrap();
let file = fs::File::open(&patch_file.path).unwrap();
let size = file.metadata().unwrap().len();
self.current_file = Some(io::BufReader::new(file));
Some(SendPatchPacket::StartFileSend(StartFileSend::new(path.to_str().unwrap(), size as u32, id)))
}
else {
self.next()
}
let patch_file = self.patch_file_lookup.get(&id).unwrap();
let file = fs::File::open(&patch_file.path).unwrap();
let size = file.metadata().unwrap().len();
self.current_file = Some(io::BufReader::new(file));
Some(SendPatchPacket::StartFileSend(StartFileSend::new(path.to_str().unwrap(), size as u32, id)))
},
PatchTreeIterItem::UpDirectory => {
Some(SendPatchPacket::UpOneDirectory(UpOneDirectory {}))

Loading…
Cancel
Save