-
Notifications
You must be signed in to change notification settings - Fork 5
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
bmap::copy also can truncate file #26
Conversation
bmap/src/lib.rs
Outdated
@@ -4,6 +4,7 @@ mod discarder; | |||
pub use crate::discarder::*; | |||
use sha2::{Digest, Sha256}; | |||
use thiserror::Error; | |||
use nix::unistd::ftruncate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to split this into two commits:
- to move the ftruncate into the
bmap::copy
function, - to call ftruncate only on a file :-)
bmap/src/lib.rs
Outdated
@@ -41,6 +42,11 @@ where | |||
HashType::Sha256 => Sha256::new(), | |||
}; | |||
|
|||
//truncate if the target is a file and not a block device | |||
match output { | |||
std::fs::OpenOptions => ftruncate(output.as_raw_fd(), map.image_size() as i64).context("Failed to truncate file")?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the clippy errors
cf31930
to
65918a5
Compare
Right now |
8c6d0f5
to
ecefb62
Compare
@@ -104,8 +102,6 @@ fn copy(c: Copy) -> Result<()> { | |||
.create(true) | |||
.open(c.dest)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think it is already being assumed that the output is going to be a file. Should this be absorbed by the copy library function too and only be executed if the output is actually a file ?
ftruncate was executed into the main function and it should be done into the copying process Signed-off-by: Rafael Garcia Ruiz <[email protected]>
ecefb62
to
c25e939
Compare
@@ -35,12 +37,14 @@ pub enum CopyError { | |||
pub fn copy<I, O>(input: &mut I, output: &mut O, map: &Bmap) -> Result<(), CopyError> | |||
where | |||
I: Read + SeekForward, | |||
O: Write + SeekForward, | |||
O: Write + SeekForward + AsRawFd, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a too heavy requirement as it will limit where we can use the copy function; E.g. that blocks using it if the output is not something that can be a raw file (e.g. if it's a usb protocol where we write to some on-device flash)
helpers mod contains functions and structs needed to setup common inputs/outputs Closes #26 Signed-off-by: Rafael Garcia Ruiz <[email protected]>
helpers mod contains functions and structs needed to setup common inputs/outputs Closes #26 Signed-off-by: Rafael Garcia Ruiz <[email protected]>
ftruncate was executed into the main function and it should be done into the copying process if it's needed
Closes: #24
Signed-off-by: Rafael Garcia Ruiz [email protected]