Skip to content

Commit

Permalink
simple_op_heads_store: propagate errors when trying to remove op head
Browse files Browse the repository at this point in the history
Any errors other than `NotFound` are unexpected.
  • Loading branch information
martinvonz committed Nov 14, 2024
1 parent de6da1a commit dfc67e7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/src/simple_op_heads_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ impl SimpleOpHeadsStore {
std::fs::write(self.dir.join(id.hex()), "")
}

fn remove_op_head(&self, id: &OperationId) {
// It's fine if the old head was not found. It probably means
// that we're on a distributed file system where the locking
// doesn't work. We'll probably end up with two current
// heads. We'll detect that next time we load the view.
// TODO: Propagate other errors than NotFound
std::fs::remove_file(self.dir.join(id.hex())).ok();
fn remove_op_head(&self, id: &OperationId) -> io::Result<()> {
std::fs::remove_file(self.dir.join(id.hex())).or_else(|err| {
if err.kind() == io::ErrorKind::NotFound {
// It's fine if the old head was not found. It probably means
// that we're on a distributed file system where the locking
// doesn't work. We'll probably end up with two current
// heads. We'll detect that next time we load the view.
Ok(())
} else {
Err(err)
}
})
}
}

Expand Down Expand Up @@ -98,7 +103,11 @@ impl OpHeadsStore for SimpleOpHeadsStore {
source: err.into(),
})?;
for old_id in old_ids {
self.remove_op_head(old_id);
self.remove_op_head(old_id)
.map_err(|err| OpHeadsStoreError::Write {
new_op_id: new_id.clone(),
source: err.into(),
})?;
}
Ok(())
}
Expand Down

0 comments on commit dfc67e7

Please sign in to comment.