I am running rustc 1.38.0 (625451e37 2019-09-23) on Fedora 30 (Workstation Edition). I am attempting to create a write-only file for test purposes. Per the standard library documentation, 'fs::OpenOptions.new().write(true).create_new(true).open("filepath")' should create a write-only file, but when I try it, the file has permissions "rw-rw-r--". I admit to being VERY new to Rust, but this seems like a contradiction to the documentation? What am I missing?
You created a write-only handle (i.e. you opened the file for writing). You did not create a write-only file in the filesystem.
Not all operating systems support the creation of a write-only file, so the standard library doesn't provide it.
You will need to use the fchmod
function in the nix
crate to access this UNIX-specific functionality.
You can set it directly on Unix targets with OpenOptionsExt::mode
.
Thank you, all! I knew I was missing something.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.