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

Drop the input before writing to the output #813

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
28 changes: 18 additions & 10 deletions topiary-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,26 @@ async fn run() -> CLIResult<()> {
output
);

let mut buf_input = BufReader::new(input);
let mut buf_output = BufWriter::new(output);

formatter(
&mut buf_input,
&mut buf_output,
&language,
Operation::Format {
skip_idempotence,
tolerate_parsing_errors,
},
)?;
{
// NOTE This newly opened scope is important! `buf_input` takes
// ownership of `input`, which -- upon reading -- contains an
// open file handle. We need to close this file, by dropping
// `buf_input`, before we attempt to persist our output.
// Otherwise, we get an exclusive lock problem on Windows.
let mut buf_input = BufReader::new(input);

formatter(
&mut buf_input,
&mut buf_output,
&language,
Operation::Format {
skip_idempotence,
tolerate_parsing_errors,
},
)?;
}

buf_output.into_inner()?.persist()?;

Expand Down
Loading