From 6d8d741652a0b445108567692c78ceaaa43ab47a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 24 Feb 2024 20:59:27 +0100 Subject: [PATCH 1/6] actions: Move away from actions-rs actions-rs is deprecated, move to dtolnay/rust-toolchain instead. Fixes: #56 Signed-off-by: Sjoerd Simons --- .github/workflows/ci.yml | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee1c85..75891a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,27 +15,20 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it with: - toolchain: stable - - uses: actions-rs/cargo@v1 - with: - command: check - args: --all-features - + toolchain: "1.70" + - run: cargo check --all-targets --all-features fmt: name: cargo fmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: actions-rs/cargo@v1 + - uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it with: - command: fmt - args: --all --check - + toolchain: "1.70" + components: rustfmt + - run: cargo fmt --all --check test: name: cargo test runs-on: ubuntu-latest @@ -43,25 +36,21 @@ jobs: - uses: actions/checkout@v4 with: lfs: 'true' - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: actions-rs/cargo@v1 + - uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it with: - command: test + toolchain: "1.70" + - run: cargo test --all-targets --all-features clippy: name: cargo clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: actions-rs/cargo@v1 + - uses: dtolnay/rust-toolchain@master # avoid the tag here to prevent dependabot from updating it with: - command: clippy - args: -- -D warnings + toolchain: "1.70" + components: clippy + - run: cargo clippy --all-targets --all-features -- -D warnings # Job to key success status against allgreen: From 05ac00e159b0abf96ff2eedc4be925e12a775641 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 24 Feb 2024 20:49:37 +0100 Subject: [PATCH 2/6] bmap-parser: require Send bounds on traits Not having the Send bound on the AsyncSeekForward trait in principle makes it easier to match. However it limits where the async copy can be used quite a bit. In particular it means it can't be used in a tokio::spawn, which is rather a big disadvantage. So start Send for the trait... Signed-off-by: Sjoerd Simons --- bmap-parser/src/discarder.rs | 4 ++-- bmap-parser/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bmap-parser/src/discarder.rs b/bmap-parser/src/discarder.rs index f9907d2..93d8c6c 100644 --- a/bmap-parser/src/discarder.rs +++ b/bmap-parser/src/discarder.rs @@ -64,8 +64,8 @@ impl AsyncRead for AsyncDiscarder { } } -#[async_trait(?Send)] -impl AsyncSeekForward for AsyncDiscarder { +#[async_trait] +impl AsyncSeekForward for AsyncDiscarder { async fn async_seek_forward(&mut self, forward: u64) -> IOResult<()> { let mut buf = [0; 4096]; let mut left = forward as usize; diff --git a/bmap-parser/src/lib.rs b/bmap-parser/src/lib.rs index 748d7f0..454403f 100644 --- a/bmap-parser/src/lib.rs +++ b/bmap-parser/src/lib.rs @@ -23,12 +23,12 @@ impl SeekForward for T { } } -#[async_trait(?Send)] +#[async_trait] pub trait AsyncSeekForward { async fn async_seek_forward(&mut self, offset: u64) -> IOResult<()>; } -#[async_trait(?Send)] +#[async_trait] impl AsyncSeekForward for T { async fn async_seek_forward(&mut self, forward: u64) -> IOResult<()> { self.seek(SeekFrom::Current(forward as i64)).await?; From 2a48a93ee4608d7f96b31ddc93af0f2695930949 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 24 Feb 2024 21:09:19 +0100 Subject: [PATCH 3/6] Bump versions to 0.2.0 Bump minor as the trait bounds have changed Signed-off-by: Sjoerd Simons --- bmap-parser/Cargo.toml | 2 +- bmap-rs/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bmap-parser/Cargo.toml b/bmap-parser/Cargo.toml index d6bb1ad..e48de78 100644 --- a/bmap-parser/Cargo.toml +++ b/bmap-parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bmap-parser" -version = "0.1.0" +version = "0.2.0" authors = ["Sjoerd Simons "] edition = "2018" license = "MIT AND Apache-2.0" diff --git a/bmap-rs/Cargo.toml b/bmap-rs/Cargo.toml index 38df423..24e1b0c 100644 --- a/bmap-rs/Cargo.toml +++ b/bmap-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bmap-rs" -version = "0.1.0" +version = "0.2.0" authors = ["Sjoerd Simons "] edition = "2018" license = "MIT AND Apache-2.0" @@ -11,7 +11,7 @@ readme = "../README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bmap-parser = { path = "../bmap-parser", version = "0.1.0"} +bmap-parser = { path = "../bmap-parser", version = "0.2.0"} anyhow = "1.0.66" nix = { version = "0.27.1", features = ["fs"] } flate2 = "1.0.24" From 497588d4012e4a1e462550fde1c38bd1709a82dc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 24 Feb 2024 21:23:31 +0100 Subject: [PATCH 4/6] clap: Pin to older clap to allow build with rust 1.70 Claps MSRV is quite aggressive, pin it to 4.4.x to allow building with rust 1.70 as currently present in debian testing. Signed-off-by: Sjoerd Simons --- bmap-rs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmap-rs/Cargo.toml b/bmap-rs/Cargo.toml index 24e1b0c..55f5ac9 100644 --- a/bmap-rs/Cargo.toml +++ b/bmap-rs/Cargo.toml @@ -15,7 +15,7 @@ bmap-parser = { path = "../bmap-parser", version = "0.2.0"} anyhow = "1.0.66" nix = { version = "0.27.1", features = ["fs"] } flate2 = "1.0.24" -clap = { version = "4.0.18", features = ["cargo"] } +clap = { version = "~4.4.0", features = ["cargo"] } indicatif = { version = "0.17.1", features = ["tokio"] } async-compression = { version = "0.4.5", features = ["gzip", "futures-io"] } tokio = { version = "1.21.2", features = ["rt", "macros", "fs", "rt-multi-thread"] } From e4479a449194167cb256ed46c7d310b05568dcb9 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 24 Feb 2024 21:29:20 +0100 Subject: [PATCH 5/6] Fix clippy warnings Signed-off-by: Sjoerd Simons --- bmap-parser/src/discarder.rs | 2 +- bmap-parser/tests/copy.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bmap-parser/src/discarder.rs b/bmap-parser/src/discarder.rs index 93d8c6c..b57f5d8 100644 --- a/bmap-parser/src/discarder.rs +++ b/bmap-parser/src/discarder.rs @@ -95,7 +95,7 @@ mod test { .iter() .fold(0, |pos, offset| { let mut byte: u8 = 1; - discarder.seek_forward((offset - pos) as u64).unwrap(); + discarder.seek_forward(offset - pos).unwrap(); assert_eq!(1, discarder.read(slice::from_mut(&mut byte)).unwrap()); assert_eq!(*offset, byte as u64); *offset + 1 diff --git a/bmap-parser/tests/copy.rs b/bmap-parser/tests/copy.rs index 910145e..28b3495 100644 --- a/bmap-parser/tests/copy.rs +++ b/bmap-parser/tests/copy.rs @@ -118,14 +118,16 @@ fn setup_data(basename: &str) -> (Bmap, impl Read + SeekForward) { let mut bmapfile = datadir.clone(); bmapfile.push(format!("{}.bmap", basename)); - let mut b = File::open(&bmapfile).expect(&format!("Failed to open bmap file:{:?}", bmapfile)); + let mut b = + File::open(&bmapfile).unwrap_or_else(|_| panic!("Failed to open bmap file:{:?}", bmapfile)); let mut xml = String::new(); b.read_to_string(&mut xml).unwrap(); let bmap = Bmap::from_xml(&xml).unwrap(); let mut datafile = datadir.clone(); datafile.push(format!("{}.gz", basename)); - let g = File::open(&datafile).expect(&format!("Failed to open data file:{:?}", datafile)); + let g = + File::open(&datafile).unwrap_or_else(|_| panic!("Failed to open data file:{:?}", datafile)); let gz = GzDecoder::new(g); let gz = Discarder::new(gz); From e3aad3203da7cf8cf2ca33da7cc48708aef42d64 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 24 Feb 2024 21:34:14 +0100 Subject: [PATCH 6/6] parser: Add basic docs for Bmap methods Signed-off-by: Sjoerd Simons --- bmap-parser/src/bmap.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bmap-parser/src/bmap.rs b/bmap-parser/src/bmap.rs index 1ce56dd..49f4f88 100644 --- a/bmap-parser/src/bmap.rs +++ b/bmap-parser/src/bmap.rs @@ -65,33 +65,42 @@ impl Bmap { BmapBuilder::default() } + /// Build from a .bmap xml file pub fn from_xml(xml: &str) -> Result { xml::from_xml(xml) } + /// Image size in bytes pub fn image_size(&self) -> u64 { self.image_size } + /// block size in bytes pub const fn block_size(&self) -> u64 { self.block_size } + /// number of blocks in the image pub fn blocks(&self) -> u64 { self.blocks } + /// number of mapped blocks in the image pub fn mapped_blocks(&self) -> u64 { self.mapped_blocks } + /// checksum type used pub fn checksum_type(&self) -> HashType { self.checksum_type } + /// Iterator over the block map pub fn block_map(&self) -> impl ExactSizeIterator + Iterator { self.blockmap.iter() } + + /// Total mapped size in bytes pub fn total_mapped_size(&self) -> u64 { self.block_size * self.mapped_blocks }