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

Function test_chmod

tests/fs/chmodat.rs:3–28  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1#[cfg(not(any(target_os = "cygwin", target_os = "wasi")))]
2#[test]
3fn test_chmod() {
4 use rustix::fs::{chmod, open, stat, symlink, Mode, OFlags};
5
6 let tmp = tempfile::tempdir().unwrap();
7
8 let _ = open(
9 tmp.path().join("file"),
10 OFlags::CREATE | OFlags::WRONLY,
11 Mode::RWXU,
12 )
13 .unwrap();
14 symlink(tmp.path().join("file"), tmp.path().join("link")).unwrap();
15
16 let before = stat(tmp.path().join("file")).unwrap();
17 assert_ne!(before.st_mode as u64 & libc::S_IRWXU as u64, 0);
18
19 chmod(tmp.path().join("file"), Mode::empty()).unwrap();
20
21 let after = stat(tmp.path().join("file")).unwrap();
22 assert_eq!(after.st_mode as u64 & libc::S_IRWXU as u64, 0);
23
24 chmod(tmp.path().join("file"), Mode::RWXU).unwrap();
25
26 let reverted = stat(tmp.path().join("file")).unwrap();
27 assert_ne!(reverted.st_mode as u64 & libc::S_IRWXU as u64, 0);
28}
29
30#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
31#[test]

Callers

nothing calls this directly

Calls 5

openFunction · 0.50
symlinkFunction · 0.50
statFunction · 0.50
chmodFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected