diff --git a/src/patch/patch.rs b/src/patch/patch.rs index 63693f9..a9ff1b3 100644 --- a/src/patch/patch.rs +++ b/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>, - file_ids_to_update: HashSet, patch_file_lookup: HashMap, current_file: Option>, 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 {})) @@ -409,4 +409,4 @@ pub fn load_motd() -> String { motd = m.clone(); } motd -} \ No newline at end of file +}