Replace old error construction code with new libimagerror functionality
This commit is contained in:
parent
2e80c29f47
commit
fdb5d1bb24
1 changed files with 11 additions and 9 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use libimagerror::into::IntoError;
|
||||||
|
|
||||||
use error::{StoreError, StoreErrorKind};
|
use error::{StoreError, StoreErrorKind};
|
||||||
use std::io::{Seek, SeekFrom};
|
use std::io::{Seek, SeekFrom};
|
||||||
|
@ -39,14 +40,15 @@ impl LazyFile {
|
||||||
// We seek to the beginning of the file since we expect each
|
// We seek to the beginning of the file since we expect each
|
||||||
// access to the file to be in a different context
|
// access to the file to be in a different context
|
||||||
f.seek(SeekFrom::Start(0))
|
f.seek(SeekFrom::Start(0))
|
||||||
.map_err(|e| StoreError::new(StoreErrorKind::FileNotCreated, Some(Box::new(e))))
|
.map_err(Box::new)
|
||||||
|
.map_err(|e| StoreErrorKind::FileNotCreated.into_error_with_cause(e))
|
||||||
.map(|_| f)
|
.map(|_| f)
|
||||||
},
|
},
|
||||||
LazyFile::Absent(ref p) => {
|
LazyFile::Absent(ref p) => {
|
||||||
try!(open_file(p).map_err(|e| {
|
try!(open_file(p)
|
||||||
StoreError::new(StoreErrorKind::FileNotFound,
|
.map_err(Box::new)
|
||||||
Some(Box::new(e)))
|
.map_err(|e| StoreErrorKind::FileNotFound.into_error_with_cause(e))
|
||||||
}))
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*self = LazyFile::File(file);
|
*self = LazyFile::File(file);
|
||||||
|
@ -64,10 +66,10 @@ impl LazyFile {
|
||||||
let file = match *self {
|
let file = match *self {
|
||||||
LazyFile::File(ref mut f) => return Ok(f),
|
LazyFile::File(ref mut f) => return Ok(f),
|
||||||
LazyFile::Absent(ref p) => {
|
LazyFile::Absent(ref p) => {
|
||||||
try!(create_file(p).map_err(|e| {
|
try!(create_file(p)
|
||||||
StoreError::new(StoreErrorKind::FileNotFound,
|
.map_err(Box::new)
|
||||||
Some(Box::new(e)))
|
.map_err(|e| StoreErrorKind::FileNotFound.into_error_with_cause(e))
|
||||||
}))
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*self = LazyFile::File(file);
|
*self = LazyFile::File(file);
|
||||||
|
|
Loading…
Reference in a new issue