add read fn

This commit is contained in:
mii443
2024-10-17 01:56:45 +00:00
parent 30d21769a3
commit 167b51b6b1

View File

@ -1,5 +1,6 @@
use std::{ use std::{
fs, fs::{self, File},
io::Read,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@ -25,6 +26,15 @@ impl CGroup {
fs::create_dir_all(root) fs::create_dir_all(root)
} }
pub fn read(&self, name: &str) -> Result<String, std::io::Error> {
let path = self.get_file_path(name);
let mut file = File::open(path)?;
let mut buf = String::default();
file.read_to_string(&mut buf)?;
Ok(buf)
}
pub fn check_status(&self) -> bool { pub fn check_status(&self) -> bool {
let root = self.get_root_path(); let root = self.get_root_path();