diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-01-27 13:58:10 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-01-27 13:58:10 +0000 |
commit | 6cef9f0fc159de4c9fd708050ec76adb4e74d390 (patch) | |
tree | 81856b3b4da6d18e10516b0be737a157e13f129b /openat/tests/tmpfile.rs | |
parent | 9e8dd00da25273fba9f0cafccbde2236e04fb24e (diff) | |
download | pam_usercg_rust-6cef9f0fc159de4c9fd708050ec76adb4e74d390.tar.gz pam_usercg_rust-6cef9f0fc159de4c9fd708050ec76adb4e74d390.tar.xz pam_usercg_rust-6cef9f0fc159de4c9fd708050ec76adb4e74d390.zip |
openat variant
Diffstat (limited to 'openat/tests/tmpfile.rs')
-rw-r--r-- | openat/tests/tmpfile.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/openat/tests/tmpfile.rs b/openat/tests/tmpfile.rs new file mode 100644 index 0000000..4fa0f0d --- /dev/null +++ b/openat/tests/tmpfile.rs @@ -0,0 +1,24 @@ +extern crate tempfile; +extern crate openat; + +use std::io::{self, Read, Write}; +use std::os::unix::fs::PermissionsExt; +use openat::Dir; + +#[test] +#[cfg(target_os="linux")] +fn unnamed_tmp_file_link() -> Result<(), io::Error> { + let tmp = tempfile::tempdir()?; + let dir = Dir::open(tmp.path())?; + let mut f = dir.new_unnamed_file(0o777)?; + f.write(b"hello\n")?; + // In glibc <= 2.22 permissions aren't set when using O_TMPFILE + // This includes ubuntu trusty on travis CI + f.set_permissions(PermissionsExt::from_mode(0o644))?; + dir.link_file_at(&f, "hello.txt")?; + let mut f = dir.open_file("hello.txt")?; + let mut buf = String::with_capacity(10); + f.read_to_string(&mut buf)?; + assert_eq!(buf, "hello\n"); + Ok(()) +} |