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::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
fs::{ File, write },
|
fs::{ File, OpenOptions },
|
||||||
io::{
|
io::{
|
||||||
Read,
|
Read,
|
||||||
stdout,
|
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 out = self.buffer.text.bytes().collect::<Vec<u8>>();
|
||||||
|
let mut handle = OpenOptions::new().write(true).open(file)?;
|
||||||
|
|
||||||
let handle = file
|
handle.write_all(out.as_slice())?;
|
||||||
.clone()
|
|
||||||
.into_string()
|
|
||||||
.map_err(|err| {
|
|
||||||
format!("{:?}", err)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
write(handle, out.as_slice())
|
|
||||||
.map_err(|err| {
|
|
||||||
format!("{:?}", err)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -380,7 +371,9 @@ impl State {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
self.write_buffer(handle)?;
|
self.write_buffer(handle).map_err(|err| {
|
||||||
|
format!("{}", err)
|
||||||
|
})?;
|
||||||
},
|
},
|
||||||
command => {
|
command => {
|
||||||
return Err(
|
return Err(
|
||||||
@ -434,7 +427,9 @@ fn main() -> Result<()> {
|
|||||||
},
|
},
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
let input_file = Path::new(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(|_| {
|
File::open(input_file).unwrap_or_else(|_| {
|
||||||
let mut err = String::new();
|
let mut err = String::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user