mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
op_store: deduplicate functions that map io::Error to OpStoreError
io_to_read_error() also translates ErrorKind::NotFound.
This commit is contained in:
parent
9533177422
commit
ea96513fd1
1 changed files with 2 additions and 10 deletions
|
@ -97,7 +97,7 @@ impl OpStore for SimpleOpStore {
|
|||
|
||||
fn read_view(&self, id: &ViewId) -> OpStoreResult<View> {
|
||||
let path = self.view_path(id);
|
||||
let buf = fs::read(path).map_err(|err| not_found_to_store_error(err, id))?;
|
||||
let buf = fs::read(path).map_err(|err| io_to_read_error(err, id))?;
|
||||
|
||||
let proto = crate::protos::op_store::View::decode(&*buf).map_err(|err| DecodeError {
|
||||
kind: "view",
|
||||
|
@ -125,7 +125,7 @@ impl OpStore for SimpleOpStore {
|
|||
|
||||
fn read_operation(&self, id: &OperationId) -> OpStoreResult<Operation> {
|
||||
let path = self.operation_path(id);
|
||||
let buf = fs::read(path).map_err(|err| not_found_to_store_error(err, id))?;
|
||||
let buf = fs::read(path).map_err(|err| io_to_read_error(err, id))?;
|
||||
|
||||
let proto =
|
||||
crate::protos::op_store::Operation::decode(&*buf).map_err(|err| DecodeError {
|
||||
|
@ -153,14 +153,6 @@ impl OpStore for SimpleOpStore {
|
|||
}
|
||||
}
|
||||
|
||||
fn not_found_to_store_error(err: std::io::Error, id: &impl ObjectId) -> OpStoreError {
|
||||
if err.kind() == ErrorKind::NotFound {
|
||||
OpStoreError::NotFound
|
||||
} else {
|
||||
io_to_read_error(err, id)
|
||||
}
|
||||
}
|
||||
|
||||
fn io_to_read_error(err: std::io::Error, id: &impl ObjectId) -> OpStoreError {
|
||||
if err.kind() == ErrorKind::NotFound {
|
||||
OpStoreError::NotFound
|
||||
|
|
Loading…
Reference in a new issue