226df7d08d
* Make our rust tests use per-thread config rather than global static This lets our unit tests run in parallel. I also moved our "integration" tests back to be unit tests for now. This also exposes a network mocking abstraction. I've added an incomplete test of applying a full patch. Still needs some work to complete. * Finish making the patch success test work * Changed our test config to use println instead of info/error, etc. so that tests show output on failure (there might be a better way?) Unfortunately macro_use (which is the way we were causing error!, info! etc to appear everywhere with only one global import before, only works on crates not on std, so I had to be explicit with my imports per-file. * Add a function to build a fake zip file, because that's what the updater currently expects. Better would be for us to move to a AssetManager system I suspect, then the updater would ask the asset manager for the libapp.so and we'd return it instead of having to go through writing out a zip file. * Added a string_patch.rs tool and shared code between that and the patch tool. This made it possible/easy for me to generate the necessary binary patches as well as needed hashes to pretend to be the patch server. * Added one simple test of the patch tool core logic. In total we're now above 80% coverage of our rust code after this. * remove stray comment
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use bidiff::DiffParams;
|
|
use std::io::{BufWriter, Seek, Write};
|
|
|
|
use comde::com::Compressor;
|
|
use comde::zstd::ZstdCompressor;
|
|
|
|
pub fn make_patch<WS>(older: Vec<u8>, newer: Vec<u8>, patch: &mut WS)
|
|
where
|
|
WS: Write + Seek,
|
|
{
|
|
let (mut patch_r, mut patch_w) = pipe::pipe();
|
|
let diff_params = DiffParams::new(1, None).unwrap();
|
|
std::thread::spawn(move || {
|
|
bidiff::simple_diff_with_params(&older[..], &newer[..], &mut patch_w, &diff_params)
|
|
.unwrap();
|
|
});
|
|
|
|
let compressor = ZstdCompressor::new();
|
|
|
|
let mut compatch_w = BufWriter::new(patch);
|
|
compressor
|
|
.compress(&mut compatch_w, &mut patch_r)
|
|
.expect("compress patch");
|
|
compatch_w.flush().expect("flush patch");
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use std::io::Cursor;
|
|
|
|
#[test]
|
|
fn test_make_patch() {
|
|
let older = b"hello world".to_vec();
|
|
let newer = b"hello world!".to_vec();
|
|
let mut patch = Cursor::new(Vec::new());
|
|
make_patch(older, newer, &mut patch);
|
|
let patch = patch.into_inner();
|
|
assert_eq!(
|
|
patch,
|
|
vec![
|
|
40, 181, 47, 253, 0, 128, 157, 0, 0, 104, 223, 177, 0, 0, 0, 16, 0, 0, 11, 0, 1,
|
|
33, 0, 1, 0, 27, 64, 2
|
|
]
|
|
);
|
|
}
|
|
}
|