forked from mars/breed
fixed file path resolution
This commit is contained in:
parent
c06b39239c
commit
6ef5182cea
25
src/main.rs
25
src/main.rs
|
@ -20,7 +20,7 @@
|
|||
use std::{
|
||||
env::args,
|
||||
ffi::OsString,
|
||||
fs::{ File, write },
|
||||
fs::{ File, OpenOptions },
|
||||
io::{
|
||||
Read,
|
||||
stdout,
|
||||
|
@ -335,20 +335,11 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
fn write_buffer(&mut self, file: OsString) -> std::result::Result<(), String> {
|
||||
fn write_buffer(&mut self, file: OsString) -> Result<()> {
|
||||
let out = self.buffer.text.bytes().collect::<Vec<u8>>();
|
||||
let mut handle = OpenOptions::new().write(true).open(file)?;
|
||||
|
||||
let handle = file
|
||||
.clone()
|
||||
.into_string()
|
||||
.map_err(|err| {
|
||||
format!("{:?}", err)
|
||||
})?;
|
||||
|
||||
write(handle, out.as_slice())
|
||||
.map_err(|err| {
|
||||
format!("{:?}", err)
|
||||
})?;
|
||||
handle.write_all(out.as_slice())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -380,7 +371,9 @@ impl State {
|
|||
};
|
||||
}
|
||||
|
||||
self.write_buffer(handle)?;
|
||||
self.write_buffer(handle).map_err(|err| {
|
||||
format!("{}", err)
|
||||
})?;
|
||||
},
|
||||
command => {
|
||||
return Err(
|
||||
|
@ -434,7 +427,9 @@ fn main() -> Result<()> {
|
|||
},
|
||||
Some(path) => {
|
||||
let input_file = Path::new(path);
|
||||
file_name = input_file.clone().file_name().map(|f| f.to_owned());
|
||||
file_name = Some(OsString::from(
|
||||
input_file.clone().display().to_string()
|
||||
));
|
||||
|
||||
File::open(input_file).unwrap_or_else(|_| {
|
||||
let mut err = String::new();
|
||||
|
|
Reference in New Issue