Skip to content

Commit

Permalink
Rework nix::unistd::ftruncate to use AsFd instead of AsRawFd
Browse files Browse the repository at this point in the history
nix::unistd::ftruncate from nix 0.27 requires the output argument to be
AsFd instead of AsRawFd. Rework the function call.

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc committed Jan 11, 2024
1 parent 4eaf8e4 commit 1bfd993
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions bmap-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::ffi::OsStr;
use std::fmt::Write;
use std::fs::File;
use std::io::Read;
use std::os::unix::io::AsRawFd;
use std::os::unix::io::AsFd;
use std::path::{Path, PathBuf};
use tokio_util::compat::TokioAsyncReadCompatExt;

Expand Down Expand Up @@ -173,10 +173,9 @@ fn setup_spinner() -> ProgressBar {
pb
}

fn setup_output<T: AsRawFd>(output: &T, bmap: &Bmap, metadata: std::fs::Metadata) -> Result<()> {
fn setup_output<T: AsFd>(output: &T, bmap: &Bmap, metadata: std::fs::Metadata) -> Result<()> {
if metadata.is_file() {
ftruncate(output.as_raw_fd(), bmap.image_size() as i64)
.context("Failed to truncate file")?;
ftruncate(output.as_fd(), bmap.image_size() as i64).context("Failed to truncate file")?;
}
Ok(())
}
Expand Down

0 comments on commit 1bfd993

Please sign in to comment.