-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make `linkat`, `unlinkat`, and `renameat` weak on macos. macOS <= 10.9 lacks these functions, so use weak symbols for them. Fixes #648. * Handle the `AT_FDCWD` cases with fallbacks. * Test with macOS 10.7. Set MACOSX_DEPLOYMENT_TARGET and MACOSX_SDK_VERSION to 10.7, currently the oldest version supported by Rust itself. * Add support for `faccessat` too. * Add some tests for `faccessat`. * Add more tests.
- Loading branch information
1 parent
7f4c3fe
commit 1dfbd05
Showing
10 changed files
with
289 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#[cfg(not(target_os = "wasi"))] | ||
#[test] | ||
fn test_chmodat() { | ||
use rustix::fs::{chmodat, cwd, openat, statat, AtFlags, Mode, OFlags}; | ||
|
||
let tmp = tempfile::tempdir().unwrap(); | ||
let dir = openat(cwd(), tmp.path(), OFlags::RDONLY, Mode::RWXU).unwrap(); | ||
|
||
let _ = openat(&dir, "foo", OFlags::CREATE | OFlags::WRONLY, Mode::RWXU).unwrap(); | ||
|
||
let before = statat(&dir, "foo", AtFlags::empty()).unwrap(); | ||
assert_ne!(before.st_mode as u64 & libc::S_IRWXU as u64, 0); | ||
|
||
chmodat(&dir, "foo", Mode::empty()).unwrap(); | ||
|
||
let after = statat(&dir, "foo", AtFlags::empty()).unwrap(); | ||
assert_eq!(after.st_mode as u64 & libc::S_IRWXU as u64, 0); | ||
|
||
chmodat(&dir, "foo", Mode::RWXU).unwrap(); | ||
|
||
let reverted = statat(&dir, "foo", AtFlags::empty()).unwrap(); | ||
assert_ne!(reverted.st_mode as u64 & libc::S_IRWXU as u64, 0); | ||
} | ||
|
||
#[cfg(not(target_os = "wasi"))] | ||
#[test] | ||
fn test_chmodat_with() { | ||
use rustix::fs::{chmodat_with, cwd, openat, statat, symlinkat, AtFlags, Mode, OFlags}; | ||
|
||
let tmp = tempfile::tempdir().unwrap(); | ||
let dir = openat(cwd(), tmp.path(), OFlags::RDONLY, Mode::RWXU).unwrap(); | ||
|
||
let _ = openat(&dir, "foo", OFlags::CREATE | OFlags::WRONLY, Mode::RWXU).unwrap(); | ||
symlinkat("foo", &dir, "link").unwrap(); | ||
|
||
match chmodat_with(&dir, "link", Mode::empty(), AtFlags::SYMLINK_NOFOLLOW) { | ||
Ok(()) => (), | ||
Err(rustix::io::Errno::OPNOTSUPP) => return, | ||
Err(e) => Err(e).unwrap(), | ||
} | ||
|
||
let before = statat(&dir, "foo", AtFlags::empty()).unwrap(); | ||
assert_ne!(before.st_mode as u64 & libc::S_IRWXU as u64, 0); | ||
|
||
chmodat_with(&dir, "foo", Mode::empty(), AtFlags::empty()).unwrap(); | ||
|
||
let after = statat(&dir, "foo", AtFlags::empty()).unwrap(); | ||
assert_eq!(after.st_mode as u64 & libc::S_IRWXU as u64, 0); | ||
|
||
chmodat_with(&dir, "foo", Mode::RWXU, AtFlags::empty()).unwrap(); | ||
|
||
let reverted = statat(&dir, "foo", AtFlags::empty()).unwrap(); | ||
assert_ne!(reverted.st_mode as u64 & libc::S_IRWXU as u64, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#[test] | ||
fn test_linkat() { | ||
use rustix::fs::{cwd, linkat, openat, readlinkat, statat, AtFlags, Mode, OFlags}; | ||
|
||
let tmp = tempfile::tempdir().unwrap(); | ||
let dir = openat(cwd(), tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap(); | ||
|
||
let _ = openat(&dir, "foo", OFlags::CREATE | OFlags::WRONLY, Mode::RUSR).unwrap(); | ||
|
||
linkat(&dir, "foo", &dir, "link", AtFlags::empty()).unwrap(); | ||
|
||
readlinkat(&dir, "foo", Vec::new()).unwrap_err(); | ||
readlinkat(&dir, "link", Vec::new()).unwrap_err(); | ||
|
||
assert_eq!( | ||
statat(&dir, "foo", AtFlags::empty()).unwrap().st_ino, | ||
statat(&dir, "link", AtFlags::empty()).unwrap().st_ino | ||
); | ||
|
||
linkat(&dir, "link", &dir, "another", AtFlags::empty()).unwrap(); | ||
|
||
assert_eq!( | ||
statat(&dir, "foo", AtFlags::empty()).unwrap().st_ino, | ||
statat(&dir, "another", AtFlags::empty()).unwrap().st_ino | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[test] | ||
fn test_readlinkat() { | ||
use rustix::fs::{cwd, openat, readlinkat, symlinkat, Mode, OFlags}; | ||
|
||
let tmp = tempfile::tempdir().unwrap(); | ||
let dir = openat(cwd(), tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap(); | ||
|
||
let _ = openat(&dir, "foo", OFlags::CREATE | OFlags::WRONLY, Mode::RUSR).unwrap(); | ||
symlinkat("foo", &dir, "link").unwrap(); | ||
|
||
readlinkat(&dir, "absent", Vec::new()).unwrap_err(); | ||
readlinkat(&dir, "foo", Vec::new()).unwrap_err(); | ||
|
||
let target = readlinkat(&dir, "link", Vec::new()).unwrap(); | ||
assert_eq!(target.to_string_lossy(), "foo"); | ||
|
||
symlinkat("link", &dir, "another").unwrap(); | ||
|
||
let target = readlinkat(&dir, "link", Vec::new()).unwrap(); | ||
assert_eq!(target.to_string_lossy(), "foo"); | ||
let target = readlinkat(&dir, "another", Vec::new()).unwrap(); | ||
assert_eq!(target.to_string_lossy(), "link"); | ||
} |
Oops, something went wrong.