Reimplement StorageBackend::put_file()
This commit is contained in:
parent
d141a3670f
commit
8bd782c1a7
1 changed files with 33 additions and 13 deletions
|
@ -89,20 +89,40 @@ impl StorageBackend {
|
||||||
*
|
*
|
||||||
* The file is moved to this function as the file won't be edited afterwards
|
* The file is moved to this function as the file won't be edited afterwards
|
||||||
*/
|
*/
|
||||||
pub fn put_file<'a, HP>(&self, f: File, p: &Parser<HP>) ->
|
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
||||||
Result<BackendOperationResult, ParserError>
|
where HP: FileHeaderParser
|
||||||
where HP: FileHeaderParser<'a>
|
|
||||||
{
|
{
|
||||||
let written = p.write(f.contents());
|
let written = write_with_parser(&f, p);
|
||||||
if let Ok(string) = written {
|
if written.is_err() { return Err(written.err().unwrap()); }
|
||||||
let path = self.build_filepath(&f);
|
let string = written.unwrap();
|
||||||
debug!("Writing file: {}", path);
|
|
||||||
debug!(" contents: {}", string);
|
let path = self.build_filepath(&f);
|
||||||
Ok(Ok(()))
|
debug!("Writing file: {}", path);
|
||||||
} else {
|
debug!(" string: {}", string);
|
||||||
debug!("Error parsing : {:?}", f.contents());
|
|
||||||
Err(written.err().unwrap())
|
FSFile::create(&path).map(|mut file| {
|
||||||
}
|
debug!("Created file at '{}'", path);
|
||||||
|
file.write_all(&string.clone().into_bytes())
|
||||||
|
.map_err(|ioerr| {
|
||||||
|
debug!("Could not write file");
|
||||||
|
let mut err = StorageBackendError::build(
|
||||||
|
"File::write_all()",
|
||||||
|
"Could not write out File contents",
|
||||||
|
None
|
||||||
|
);
|
||||||
|
err.caused_by = Some(Box::new(ioerr));
|
||||||
|
err
|
||||||
|
})
|
||||||
|
}).map_err(|writeerr| {
|
||||||
|
debug!("Could not create file at '{}'", path);
|
||||||
|
let mut err = StorageBackendError::build(
|
||||||
|
"File::create()",
|
||||||
|
"Creating file on disk failed",
|
||||||
|
None
|
||||||
|
);
|
||||||
|
err.caused_by = Some(Box::new(writeerr));
|
||||||
|
err
|
||||||
|
}).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue