summaryrefslogtreecommitdiffstats
path: root/vendor/nix/test/sys/test_stat.rs
blob: 426b4b6588eb7fb48808dd2465019ce93c40ccf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// The conversion is not useless on all platforms.
#[allow(clippy::useless_conversion)]
#[cfg(target_os = "freebsd")]
#[test]
fn test_chflags() {
    use nix::{
        sys::stat::{fstat, FileFlag},
        unistd::chflags,
    };
    use std::os::unix::io::AsRawFd;
    use tempfile::NamedTempFile;

    let f = NamedTempFile::new().unwrap();

    let initial = FileFlag::from_bits_truncate(
        fstat(f.as_raw_fd()).unwrap().st_flags.into(),
    );
    // UF_OFFLINE is preserved by all FreeBSD file systems, but not interpreted
    // in any way, so it's handy for testing.
    let commanded = initial ^ FileFlag::UF_OFFLINE;

    chflags(f.path(), commanded).unwrap();

    let changed = FileFlag::from_bits_truncate(
        fstat(f.as_raw_fd()).unwrap().st_flags.into(),
    );

    assert_eq!(commanded, changed);
}