emma
/
breed
Archived
forked from mars/breed
1
0
Fork 0

fixed file path resolution

This commit is contained in:
Emma Tebibyte 2023-04-12 12:44:37 -04:00
parent c06b39239c
commit 6ef5182cea
1 changed files with 10 additions and 15 deletions

View File

@ -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();