Skip to content

Commit

Permalink
linera-client: improve error behaviour on open failure (linera-io#2738
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Twey authored Oct 29, 2024
1 parent 95cdf68 commit 87ae4cd
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions linera-client/src/persistent/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,16 @@ impl<T: serde::Serialize + serde::de::DeserializeOwned> File<T> {
) -> Result<Self, Error> {
let lock = Lock::new(open_options().read(true).open(path)?)?;
let mut reader = io::BufReader::new(&lock.0);
let dirty;

let value = if reader.fill_buf()?.is_empty() {
dirty = Dirty::new(true);
value()?
} else {
dirty = Dirty::new(false);
serde_json::from_reader(reader)?
};
let file_is_empty = reader.fill_buf()?.is_empty();

Ok(Self {
value,
value: if file_is_empty {
value()?
} else {
serde_json::from_reader(reader)?
},
dirty: Dirty::new(file_is_empty),
path: path.into(),
dirty,
_lock: lock,
})
}
Expand Down

0 comments on commit 87ae4cd

Please sign in to comment.