MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_file

Function test_file

tests/fs/file.rs:14–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12#[cfg(not(target_os = "redox"))]
13#[test]
14fn test_file() {
15 rustix::fs::accessat(
16 rustix::fs::CWD,
17 "Cargo.toml",
18 rustix::fs::Access::READ_OK,
19 rustix::fs::AtFlags::empty(),
20 )
21 .unwrap();
22
23 rustix::fs::chown("Cargo.toml", None, None).unwrap();
24
25 #[cfg(not(any(target_os = "android", target_os = "emscripten")))]
26 #[allow(unreachable_patterns)]
27 match rustix::fs::accessat(
28 rustix::fs::CWD,
29 "Cargo.toml",
30 rustix::fs::Access::READ_OK,
31 rustix::fs::AtFlags::EACCESS,
32 ) {
33 Ok(()) => (),
34 Err(
35 rustix::io::Errno::NOSYS | rustix::io::Errno::NOTSUP | rustix::io::Errno::OPNOTSUPP,
36 ) => {
37 #[cfg(feature = "process")]
38 if rustix::process::getuid() == rustix::process::geteuid()
39 && rustix::process::getgid() == rustix::process::getegid()
40 {
41 panic!(
42 "accessat with EACCESS should always work when the effective uid/gid match \
43 the real uid/gid"
44 )
45 }
46 }
47 Err(err) => panic!("{:?}", err),
48 }
49
50 // Check that `SYMLINK_FOLLOW` is rejected. Except on NetBSD which seems to
51 // permit it.
52 #[cfg(not(target_os = "netbsd"))]
53 assert_eq!(
54 rustix::fs::accessat(
55 rustix::fs::CWD,
56 "Cargo.toml",
57 rustix::fs::Access::READ_OK,
58 rustix::fs::AtFlags::SYMLINK_FOLLOW,
59 ),
60 Err(rustix::io::Errno::INVAL)
61 );
62
63 assert_eq!(
64 rustix::fs::openat(
65 rustix::fs::CWD,
66 "Cagro.motl",
67 rustix::fs::OFlags::RDONLY,
68 rustix::fs::Mode::empty(),
69 )
70 .unwrap_err(),
71 rustix::io::Errno::NOENT

Callers

nothing calls this directly

Calls 15

accessatFunction · 0.50
chownFunction · 0.50
getuidFunction · 0.50
geteuidFunction · 0.50
getgidFunction · 0.50
getegidFunction · 0.50
openatFunction · 0.50
fchownFunction · 0.50
fadviseFunction · 0.50
fsyncFunction · 0.50
fdatasyncFunction · 0.50
fcntl_getflFunction · 0.50

Tested by

no test coverage detected