Reimplement StorageBackend::put_file()

This commit is contained in:
Matthias Beyer 2015-12-02 11:43:11 +01:00
parent d141a3670f
commit 8bd782c1a7

View file

@ -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 string = written.unwrap();
let path = self.build_filepath(&f); let path = self.build_filepath(&f);
debug!("Writing file: {}", path); debug!("Writing file: {}", path);
debug!(" contents: {}", string); debug!(" string: {}", string);
Ok(Ok(()))
} else { FSFile::create(&path).map(|mut file| {
debug!("Error parsing : {:?}", f.contents()); debug!("Created file at '{}'", path);
Err(written.err().unwrap()) 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(()))
} }
/* /*