Reimplement StorageBackend::put_file()
This commit is contained in:
parent
21d889e1e2
commit
e0fefc3da4
1 changed files with 17 additions and 6 deletions
|
@ -109,7 +109,18 @@ impl StorageBackend {
|
||||||
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
let written = write_with_parser(&f, p);
|
let written = p.write(f.contents())
|
||||||
|
.or_else(|err| {
|
||||||
|
let mut serr = StorageBackendError::build(
|
||||||
|
"Parser::write()",
|
||||||
|
"Cannot parse file contents",
|
||||||
|
"Cannot translate internal representation of file contents into on-disk representation",
|
||||||
|
None
|
||||||
|
);
|
||||||
|
serr.caused_by = Some(&err);
|
||||||
|
Err(serr)
|
||||||
|
});
|
||||||
|
|
||||||
if written.is_err() { return Err(written.err().unwrap()); }
|
if written.is_err() { return Err(written.err().unwrap()); }
|
||||||
let string = written.unwrap();
|
let string = written.unwrap();
|
||||||
|
|
||||||
|
@ -117,7 +128,7 @@ impl StorageBackend {
|
||||||
debug!("Writing file: {}", path);
|
debug!("Writing file: {}", path);
|
||||||
debug!(" string: {}", string);
|
debug!(" string: {}", string);
|
||||||
|
|
||||||
FSFile::create(&path).map(|mut file| {
|
FSFile::create(&path).map(|file| {
|
||||||
debug!("Created file at '{}'", path);
|
debug!("Created file at '{}'", path);
|
||||||
file.write_all(&string.clone().into_bytes())
|
file.write_all(&string.clone().into_bytes())
|
||||||
.map_err(|ioerr| {
|
.map_err(|ioerr| {
|
||||||
|
@ -125,9 +136,9 @@ impl StorageBackend {
|
||||||
let mut err = StorageBackendError::build(
|
let mut err = StorageBackendError::build(
|
||||||
"File::write_all()",
|
"File::write_all()",
|
||||||
"Could not write out File contents",
|
"Could not write out File contents",
|
||||||
None
|
"", None
|
||||||
);
|
);
|
||||||
err.caused_by = Some(Box::new(ioerr));
|
err.caused_by = Some(&ioerr);
|
||||||
err
|
err
|
||||||
})
|
})
|
||||||
}).map_err(|writeerr| {
|
}).map_err(|writeerr| {
|
||||||
|
@ -135,7 +146,7 @@ impl StorageBackend {
|
||||||
let mut err = StorageBackendError::build(
|
let mut err = StorageBackendError::build(
|
||||||
"File::create()",
|
"File::create()",
|
||||||
"Creating file on disk failed",
|
"Creating file on disk failed",
|
||||||
None
|
"", None
|
||||||
);
|
);
|
||||||
err.caused_by = Some(Box::new(writeerr));
|
err.caused_by = Some(Box::new(writeerr));
|
||||||
err
|
err
|
||||||
|
@ -263,7 +274,7 @@ impl<'a> StorageBackendError<'a> {
|
||||||
|
|
||||||
fn build(action: &'static str,
|
fn build(action: &'static str,
|
||||||
desc: &'static str,
|
desc: &'static str,
|
||||||
data : Option<String>) -> StorageBackendError
|
data : Option<String>) -> StorageBackendError<'a>
|
||||||
{
|
{
|
||||||
StorageBackendError {
|
StorageBackendError {
|
||||||
action: String::from(action),
|
action: String::from(action),
|
||||||
|
|
Loading…
Reference in a new issue