| 1 | // The conversion is not useless on all platforms. |
| 2 | #[allow (clippy::useless_conversion)] |
| 3 | #[cfg (target_os = "freebsd" )] |
| 4 | #[test] |
| 5 | fn test_chflags() { |
| 6 | use nix::{ |
| 7 | sys::stat::{fstat, FileFlag}, |
| 8 | unistd::chflags, |
| 9 | }; |
| 10 | use std::os::unix::io::AsRawFd; |
| 11 | use tempfile::NamedTempFile; |
| 12 | |
| 13 | let f = NamedTempFile::new().unwrap(); |
| 14 | |
| 15 | let initial = FileFlag::from_bits_truncate( |
| 16 | fstat(f.as_raw_fd()).unwrap().st_flags.into(), |
| 17 | ); |
| 18 | // UF_OFFLINE is preserved by all FreeBSD file systems, but not interpreted |
| 19 | // in any way, so it's handy for testing. |
| 20 | let commanded = initial ^ FileFlag::UF_OFFLINE; |
| 21 | |
| 22 | chflags(f.path(), commanded).unwrap(); |
| 23 | |
| 24 | let changed = FileFlag::from_bits_truncate( |
| 25 | fstat(f.as_raw_fd()).unwrap().st_flags.into(), |
| 26 | ); |
| 27 | |
| 28 | assert_eq!(commanded, changed); |
| 29 | } |
| 30 | |