refactor all write_alls to ensure flushing (#5567)

This commit is contained in:
Darren Schroeder
2022-05-17 13:28:18 -05:00
committed by GitHub
parent f26d3bf8d7
commit f0cb2f38df
14 changed files with 85 additions and 85 deletions

View File

@ -5,7 +5,6 @@ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value,
};
use std::io::{BufWriter, Write};
use std::path::Path;
#[derive(Clone)]
@ -100,6 +99,8 @@ impl Command for Save {
Value::String { val, .. } => {
if let Err(err) = file.write_all(val.as_bytes()) {
return Err(ShellError::IOError(err.to_string()));
} else {
file.flush()?
}
Ok(PipelineData::new(span))
@ -107,6 +108,8 @@ impl Command for Save {
Value::Binary { val, .. } => {
if let Err(err) = file.write_all(&val) {
return Err(ShellError::IOError(err.to_string()));
} else {
file.flush()?
}
Ok(PipelineData::new(span))
@ -121,6 +124,8 @@ impl Command for Save {
if let Err(err) = file.write_all(val.as_bytes()) {
return Err(ShellError::IOError(err.to_string()));
} else {
file.flush()?
}
Ok(PipelineData::new(span))
@ -166,6 +171,8 @@ impl Command for Save {
Value::String { val, .. } => {
if let Err(err) = file.write_all(val.as_bytes()) {
return Err(ShellError::IOError(err.to_string()));
} else {
file.flush()?
}
Ok(PipelineData::new(span))
@ -173,6 +180,8 @@ impl Command for Save {
Value::Binary { val, .. } => {
if let Err(err) = file.write_all(&val) {
return Err(ShellError::IOError(err.to_string()));
} else {
file.flush()?
}
Ok(PipelineData::new(span))
@ -187,6 +196,8 @@ impl Command for Save {
if let Err(err) = file.write_all(val.as_bytes()) {
return Err(ShellError::IOError(err.to_string()));
} else {
file.flush()?
}
Ok(PipelineData::new(span))

View File

@ -68,7 +68,8 @@ fn save_append_will_not_overwrite_content() {
let mut file =
std::fs::File::create(&expected_file).expect("Failed to create test file");
file.write_all("hello ".as_bytes())
.expect("Failed to write to test file")
.expect("Failed to write to test file");
file.flush().expect("Failed to flush io")
}
nu!(