mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Panic if config file is bad
This commit is contained in:
@@ -30,18 +30,18 @@ impl Config {
|
|||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(&CONFIG_PATH)
|
.open(&CONFIG_PATH)
|
||||||
.expect(&format!("The file {} or directory /etc/asusd/ is missing", CONFIG_PATH)); // okay to cause panic here
|
.expect(&format!(
|
||||||
|
"The file {} or directory /etc/asusd/ is missing",
|
||||||
|
CONFIG_PATH
|
||||||
|
)); // okay to cause panic here
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
self = Config::create_default(&mut file, &supported_led_modes);
|
self = Config::create_default(&mut file, &supported_led_modes);
|
||||||
} else {
|
} else {
|
||||||
self = serde_json::from_str(&buf).unwrap_or_else(|_| {
|
self = serde_json::from_str(&buf).unwrap_or_else(|_| {
|
||||||
warn!(
|
warn!("Could not deserialise {}", CONFIG_PATH);
|
||||||
"Could not deserialise {}. Overwriting with default",
|
panic!("Please remove {} then restart asusd", CONFIG_PATH);
|
||||||
CONFIG_PATH
|
|
||||||
);
|
|
||||||
Config::create_default(&mut file, &supported_led_modes)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user