diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-08-06 02:11:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-06 02:11:37 +0000 |
commit | a10078f35c9564950035dfc88cb3a2cd9f3d9be3 (patch) | |
tree | e171da249e57ded5ab6ea3349b9d7fdf46493e5b /test | |
parent | 67329c593f2482f5278b76fb436c7db79c921521 (diff) | |
parent | f8c79c63e5b2779f4b1d4f5e113541cadb51b32f (diff) | |
download | nix-a10078f35c9564950035dfc88cb3a2cd9f3d9be3.zip |
Merge #1780
1780: Implement faccessat r=asomers a=nateavers
This is a re-post of #1134, which seems to have been abandoned. Includes the changes requested in [this comment](https://github.com/nix-rust/nix/pull/1134#issuecomment-541346612).
Co-authored-by: Zhang Miaolei <zmlcc@outlook.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_unistd.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 337ebe46..b08ab332 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1308,3 +1308,71 @@ fn test_getpeereid_invalid_fd() { // getpeereid is not POSIX, so error codes are inconsistent between different Unices. getpeereid(-1).expect_err("assertion failed"); } + +#[test] +#[cfg(not(any(target_os = "illumos", target_os = "redox")))] +fn test_faccessat_none_not_existing() { + use nix::fcntl::AtFlags; + let tempdir = tempfile::tempdir().unwrap(); + let dir = tempdir.path().join("does_not_exist.txt"); + assert_eq!( + faccessat(None, &dir, AccessFlags::F_OK, AtFlags::empty()) + .err() + .unwrap(), + Errno::ENOENT + ); +} + +#[test] +#[cfg(not(any(target_os = "illumos", target_os = "redox")))] +fn test_faccessat_not_existing() { + use nix::fcntl::AtFlags; + let tempdir = tempfile::tempdir().unwrap(); + let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let not_exist_file = "does_not_exist.txt"; + assert_eq!( + faccessat( + Some(dirfd), + not_exist_file, + AccessFlags::F_OK, + AtFlags::empty() + ) + .err() + .unwrap(), + Errno::ENOENT + ); +} + +#[test] +#[cfg(not(any(target_os = "illumos", target_os = "redox")))] +fn test_faccessat_none_file_exists() { + use nix::fcntl::AtFlags; + let tempdir = tempfile::tempdir().unwrap(); + let path = tempdir.path().join("does_exist.txt"); + let _file = File::create(path.clone()).unwrap(); + assert!(faccessat( + None, + &path, + AccessFlags::R_OK | AccessFlags::W_OK, + AtFlags::empty() + ) + .is_ok()); +} + +#[test] +#[cfg(not(any(target_os = "illumos", target_os = "redox")))] +fn test_faccessat_file_exists() { + use nix::fcntl::AtFlags; + let tempdir = tempfile::tempdir().unwrap(); + let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let exist_file = "does_exist.txt"; + let path = tempdir.path().join(exist_file); + let _file = File::create(path.clone()).unwrap(); + assert!(faccessat( + Some(dirfd), + &path, + AccessFlags::R_OK | AccessFlags::W_OK, + AtFlags::empty() + ) + .is_ok()); +} |