Skip to content

Commit bff1d53

Browse files
authored
Fix the test_ioctl_ficlone test to work on more filesystems. (#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.
1 parent ec767e8 commit bff1d53

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/io/ioctl.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ fn test_ioctls() {
2525
target_arch = "sparc64"
2626
)))]
2727
#[test]
28-
fn test_ioctl_fioclone() {
28+
fn test_ioctl_ficlone() {
29+
use rustix::io;
30+
2931
let src = std::fs::File::open("Cargo.toml").unwrap();
3032
let dest = tempfile::tempfile().unwrap();
31-
rustix::io::ioctl_ficlone(&dest, &dest).unwrap_err();
32-
rustix::io::ioctl_ficlone(&src, &src).unwrap_err();
33+
let dir = tempfile::tempdir().unwrap();
34+
let dir = std::fs::File::open(dir.path()).unwrap();
35+
36+
// `src` isn't opened for writing, so passing it as the output fails.
37+
assert_eq!(rustix::io::ioctl_ficlone(&src, &src), Err(io::Errno::BADF));
38+
39+
// `FICLONE` operates on regular files, not directories.
40+
assert_eq!(rustix::io::ioctl_ficlone(&dir, &dir), Err(io::Errno::ISDIR));
3341

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

0 commit comments

Comments
 (0)