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: 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-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 } diff --git a/bmap-parser/src/discarder.rs b/bmap-parser/src/discarder.rs index f9907d2..b57f5d8 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; @@ -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/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?; 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); diff --git a/bmap-rs/Cargo.toml b/bmap-rs/Cargo.toml index 38df423..55f5ac9 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,11 +11,11 @@ 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" -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"] }