Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore append when truncate is set #4394

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/virtual-fs/src/host_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,20 @@ impl crate::FileOpener for FileSystem {
// TODO: handle create implying write, etc.
let read = conf.read();
let write = conf.write();
let append = conf.append();

// according to Rust's stdlib, specifying both truncate and append is nonsensical,
// and it will return an error if we try to open a file with both flags set.
// in order to prevent this, and stay compatible with native binaries, we just ignore
// the append flag if truncate is set. the rationale behind this decision is that
// truncate is going to be applied first and append is going to be ignored anyway.
let append = if conf.truncate { false } else { conf.append() };

let mut oo = fs::OpenOptions::new();
oo.read(conf.read())
.write(conf.write())
.create_new(conf.create_new())
.create(conf.create())
.append(conf.append())
.append(append)
.truncate(conf.truncate())
.open(path)
.map_err(Into::into)
Expand Down
Loading