| 1 | #[cfg(not(any(target_os = "cygwin", target_os = "wasi")))] |
| 2 | #[test] |
| 3 | fn 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] |