Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/backends/qemu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use serde::{Deserialize, Serialize};

use crate::{
backends::{Backend, BackendClientError, BackendRegistration},
config::{ConfigError, load_config},
config::ConfigError,
instance::{Instance, InstanceClient},
util::Path,
};
Expand Down Expand Up @@ -82,12 +82,12 @@ impl QemuConfig {
/// Read `<dir>/qemu.json` if present, otherwise return the
/// built-in defaults.
pub fn from_dir(dir: &Path) -> Result<Self, ConfigError> {
let path = Path::new(&dir.join("qemu.json"));
if path.exists() {
load_config(path)
} else {
Ok(Self::default())
let path = dir.join("qemu.json");
if !path.exists() {
return Ok(Self::default());
}
let data = std::fs::read_to_string(&path)?;
Ok(serde_json::from_str(&data)?)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/engines/threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ impl ThresholdEngine {

/// Load `threshold.json`, falling back to built-in defaults when absent.
pub fn from_config_dir(dir: &Path) -> Result<Self, EngineError> {
let path = Path::new(&dir.join(format!("{ENGINE_NAME}.json")));
// TODO TOCTOU, blindly load and return default if ENOENT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep TODO (and repeat in L86) or fix now?

let path = dir.join(format!("{ENGINE_NAME}.json"));
let cfg: ThresholdConfig = if path.exists() {
crate::config::load_config(path)?
let data = std::fs::read_to_string(&path).map_err(ConfigError::from)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to extend ConfigError to avoid the map_err?

serde_json::from_str(&data).map_err(ConfigError::from)?
} else {
ThresholdConfig::default()
};
Expand Down
Loading