mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
fs: fix read() typesig
This commit is contained in:
parent
91cef3b8b1
commit
543e5a052e
3 changed files with 11 additions and 10 deletions
|
@ -86,7 +86,7 @@ impl Cpu {
|
||||||
pub fn get_available_governors(&self) -> Vec<String> {
|
pub fn get_available_governors(&self) -> Vec<String> {
|
||||||
let Self { number, .. } = self;
|
let Self { number, .. } = self;
|
||||||
|
|
||||||
let Ok(Some(content)) = fs::read(format!(
|
let Some(Ok(content)) = fs::read(format!(
|
||||||
"/sys/devices/system/cpu/cpu{number}/cpufreq/scaling_available_governors"
|
"/sys/devices/system/cpu/cpu{number}/cpufreq/scaling_available_governors"
|
||||||
)) else {
|
)) else {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
|
@ -127,7 +127,7 @@ impl Cpu {
|
||||||
pub fn get_available_epps(&self) -> Vec<String> {
|
pub fn get_available_epps(&self) -> Vec<String> {
|
||||||
let Self { number, .. } = self;
|
let Self { number, .. } = self;
|
||||||
|
|
||||||
let Ok(Some(content)) = fs::read(format!(
|
let Some(Ok(content)) = fs::read(format!(
|
||||||
"/sys/devices/system/cpu/cpu{number}/cpufreq/energy_performance_available_preferences"
|
"/sys/devices/system/cpu/cpu{number}/cpufreq/energy_performance_available_preferences"
|
||||||
)) else {
|
)) else {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
|
|
12
src/fs.rs
12
src/fs.rs
|
@ -15,17 +15,17 @@ pub fn read_dir(path: impl AsRef<Path>) -> anyhow::Result<fs::ReadDir> {
|
||||||
.with_context(|| format!("failed to read directory '{path}'", path = path.display()))
|
.with_context(|| format!("failed to read directory '{path}'", path = path.display()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(path: impl AsRef<Path>) -> anyhow::Result<Option<String>> {
|
pub fn read(path: impl AsRef<Path>) -> Option<anyhow::Result<String>> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
match fs::read_to_string(path) {
|
match fs::read_to_string(path) {
|
||||||
Ok(string) => Ok(Some(string)),
|
Ok(string) => Some(Ok(string)),
|
||||||
|
|
||||||
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(None),
|
Err(error) if error.kind() == io::ErrorKind::NotFound => None,
|
||||||
|
|
||||||
Err(error) => {
|
Err(error) => Some(
|
||||||
Err(error).with_context(|| format!("failed to read '{path}", path = path.display()))
|
Err(error).with_context(|| format!("failed to read '{path}", path = path.display())),
|
||||||
}
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,9 +127,10 @@ impl PowerSupply {
|
||||||
let type_path = self.path.join("type");
|
let type_path = self.path.join("type");
|
||||||
|
|
||||||
let type_ = fs::read(&type_path)
|
let type_ = fs::read(&type_path)
|
||||||
|
.with_context(|| format!("'{path}' doesn't exist", path = type_path.display()))?
|
||||||
.with_context(|| format!("failed to read '{path}'", path = type_path.display()))?;
|
.with_context(|| format!("failed to read '{path}'", path = type_path.display()))?;
|
||||||
|
|
||||||
type_.ok_or_else(|| anyhow!("'{path}' doesn't exist", path = type_path.display()))
|
Ok(type_)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
||||||
|
@ -206,7 +207,7 @@ impl PowerSupply {
|
||||||
pub fn get_available_platform_profiles() -> Vec<String> {
|
pub fn get_available_platform_profiles() -> Vec<String> {
|
||||||
let path = "/sys/firmware/acpi/platform_profile_choices";
|
let path = "/sys/firmware/acpi/platform_profile_choices";
|
||||||
|
|
||||||
let Ok(Some(content)) = fs::read(path) else {
|
let Some(Ok(content)) = fs::read(path) else {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue