mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 21:48:42 +00:00
Fix err handling in Crates2Json::append_to_path
Only uses `Self::default()` if the file is not found. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
1e725a9ffe
commit
fb3e35624b
1 changed files with 9 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet},
|
collections::{BTreeMap, BTreeSet},
|
||||||
fs,
|
fs, io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,7 +69,13 @@ impl Crates2Json {
|
||||||
cvs: CrateVersionSource,
|
cvs: CrateVersionSource,
|
||||||
info: CrateInfo,
|
info: CrateInfo,
|
||||||
) -> Result<(), Crates2JsonParseError> {
|
) -> Result<(), Crates2JsonParseError> {
|
||||||
let mut c2 = Self::load_from_path(path.as_ref()).unwrap_or_default();
|
let mut c2 = match Self::load_from_path(path.as_ref()) {
|
||||||
|
Ok(c2) => c2,
|
||||||
|
Err(Crates2JsonParseError::Io(io_err)) if io_err.kind() == io::ErrorKind::NotFound => {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
};
|
||||||
c2.insert(cvs, info);
|
c2.insert(cvs, info);
|
||||||
c2.write_to_path(path.as_ref())?;
|
c2.write_to_path(path.as_ref())?;
|
||||||
|
|
||||||
|
@ -84,7 +90,7 @@ impl Crates2Json {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
pub enum Crates2JsonParseError {
|
pub enum Crates2JsonParseError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] io::Error),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Json(#[from] serde_json::Error),
|
Json(#[from] serde_json::Error),
|
||||||
|
|
Loading…
Add table
Reference in a new issue