Overwrite output file if already present.
File::open() opens in read only mode. Has been modified to OpenOptions to be able to both create the file if it doensn't exist, and truncate and write if it does. Fixes #34
This commit is contained in:
parent
fdf8e6136c
commit
c09e3dccd6
10
src/main.rs
10
src/main.rs
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::OpenOptions,
|
||||||
io::{stdin, stdout, BufWriter, Read, Write},
|
io::{stdin, stdout, BufWriter, Read, Write},
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
@ -191,7 +191,13 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let (mut stdout_write, mut file_write);
|
let (mut stdout_write, mut file_write);
|
||||||
let buf_out: &mut dyn Write = if let Some(path) = matches.value_of("OUTPUT") {
|
let buf_out: &mut dyn Write = if let Some(path) = matches.value_of("OUTPUT") {
|
||||||
file_write = BufWriter::new(File::open(path).unwrap_or(File::create(path)?));
|
file_write = BufWriter::new(
|
||||||
|
OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(path)?,
|
||||||
|
);
|
||||||
&mut file_write
|
&mut file_write
|
||||||
} else {
|
} else {
|
||||||
stdout_write = BufWriter::new(stdout());
|
stdout_write = BufWriter::new(stdout());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user