Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates #78

Merged
merged 6 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,42 @@ 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
steps:
- 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:
Expand Down
2 changes: 1 addition & 1 deletion bmap-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bmap-parser"
version = "0.1.0"
version = "0.2.0"
authors = ["Sjoerd Simons <[email protected]>"]
edition = "2018"
license = "MIT AND Apache-2.0"
Expand Down
9 changes: 9 additions & 0 deletions bmap-parser/src/bmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,42 @@ impl Bmap {
BmapBuilder::default()
}

/// Build from a .bmap xml file
pub fn from_xml(xml: &str) -> Result<Self, xml::XmlError> {
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<Item = &BlockRange> {
self.blockmap.iter()
}

/// Total mapped size in bytes
pub fn total_mapped_size(&self) -> u64 {
self.block_size * self.mapped_blocks
}
Expand Down
6 changes: 3 additions & 3 deletions bmap-parser/src/discarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl<R: AsyncRead + Unpin> AsyncRead for AsyncDiscarder<R> {
}
}

#[async_trait(?Send)]
impl<R: AsyncRead + Unpin> AsyncSeekForward for AsyncDiscarder<R> {
#[async_trait]
impl<R: AsyncRead + Unpin + Send> AsyncSeekForward for AsyncDiscarder<R> {
async fn async_seek_forward(&mut self, forward: u64) -> IOResult<()> {
let mut buf = [0; 4096];
let mut left = forward as usize;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bmap-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ impl<T: Seek> 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<T: AsyncSeek + Unpin + Send> AsyncSeekForward for T {
async fn async_seek_forward(&mut self, forward: u64) -> IOResult<()> {
self.seek(SeekFrom::Current(forward as i64)).await?;
Expand Down
6 changes: 4 additions & 2 deletions bmap-parser/tests/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions bmap-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bmap-rs"
version = "0.1.0"
version = "0.2.0"
authors = ["Sjoerd Simons <[email protected]>"]
edition = "2018"
license = "MIT AND Apache-2.0"
Expand All @@ -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"] }
Expand Down