Skip to content

Commit

Permalink
Fix the test_ioctl_ficlone test to work on more filesystems. (bytec…
Browse files Browse the repository at this point in the history
…odealliance#659)

Rename the typo `test_ioctl_fioclone` to `test_ioctl_ficlone`, and fix
it to avoid depending on the ioctl always failing, as there are
filesystems on which it doesn't always fail.
  • Loading branch information
sunfishcode authored May 5, 2023
1 parent ec767e8 commit bff1d53
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/io/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ fn test_ioctls() {
target_arch = "sparc64"
)))]
#[test]
fn test_ioctl_fioclone() {
fn test_ioctl_ficlone() {
use rustix::io;

let src = std::fs::File::open("Cargo.toml").unwrap();
let dest = tempfile::tempfile().unwrap();
rustix::io::ioctl_ficlone(&dest, &dest).unwrap_err();
rustix::io::ioctl_ficlone(&src, &src).unwrap_err();
let dir = tempfile::tempdir().unwrap();
let dir = std::fs::File::open(dir.path()).unwrap();

// `src` isn't opened for writing, so passing it as the output fails.
assert_eq!(rustix::io::ioctl_ficlone(&src, &src), Err(io::Errno::BADF));

// `FICLONE` operates on regular files, not directories.
assert_eq!(rustix::io::ioctl_ficlone(&dir, &dir), Err(io::Errno::ISDIR));

// Not all filesystems support this, so we can't assert that it passes.
rustix::io::ioctl_ficlone(&dest, &src).ok();
// Now try something that might succeed, though be prepared for filesystems
// that don't support this.
match rustix::io::ioctl_ficlone(&dest, &src) {
Ok(()) | Err(io::Errno::OPNOTSUPP) => (),
Err(err) => Err(err).unwrap(),
}
}

0 comments on commit bff1d53

Please sign in to comment.