mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-28 01:17:45 +00:00
battery: bettery error handling in sysfs value reading
This commit is contained in:
parent
6c2fc6652f
commit
a3137ff2d0
1 changed files with 6 additions and 5 deletions
|
@ -167,10 +167,12 @@ fn read_sysfs_value(path: impl AsRef<Path>) -> Result<String> {
|
||||||
fs::read_to_string(p)
|
fs::read_to_string(p)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
let error_msg = format!("Path: {:?}, Error: {}", p.display(), e);
|
let error_msg = format!("Path: {:?}, Error: {}", p.display(), e);
|
||||||
if e.kind() == io::ErrorKind::PermissionDenied {
|
match e.kind() {
|
||||||
ControlError::PermissionDenied(error_msg)
|
io::ErrorKind::PermissionDenied => ControlError::PermissionDenied(error_msg),
|
||||||
} else {
|
io::ErrorKind::NotFound => {
|
||||||
ControlError::ReadError(error_msg)
|
ControlError::PathMissing(format!("Path '{}' does not exist", p.display()))
|
||||||
|
}
|
||||||
|
_ => ControlError::ReadError(error_msg),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|s| s.trim().to_string())
|
.map(|s| s.trim().to_string())
|
||||||
|
@ -220,7 +222,6 @@ fn apply_thresholds_to_batteries(
|
||||||
let stop_path = battery.path.join(battery.pattern.stop_path);
|
let stop_path = battery.path.join(battery.pattern.stop_path);
|
||||||
|
|
||||||
// Read current thresholds in case we need to restore them
|
// Read current thresholds in case we need to restore them
|
||||||
let current_start = read_sysfs_value(&start_path).ok();
|
|
||||||
let current_stop = read_sysfs_value(&stop_path).ok();
|
let current_stop = read_sysfs_value(&stop_path).ok();
|
||||||
|
|
||||||
// Write stop threshold first (must be >= start threshold)
|
// Write stop threshold first (must be >= start threshold)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue