mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-16 03:06:47 -04:00
power: Make sure to flush writes before dropping the files
This commit is contained in:
parent
e3122059e5
commit
f004035f7f
2 changed files with 18 additions and 16 deletions
10
src/main.rs
10
src/main.rs
|
@ -6,7 +6,9 @@
|
|||
*/
|
||||
|
||||
use anyhow::{anyhow, bail, Error, Result};
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tokio::fs::File;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
use tokio::task::JoinSet;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
@ -76,6 +78,12 @@ pub fn path<S: AsRef<str>>(path: S) -> PathBuf {
|
|||
.join(path.as_ref().trim_start_matches('/'))
|
||||
}
|
||||
|
||||
pub async fn write_synced<P: AsRef<Path>>(path: P, bytes: &[u8]) -> Result<()> {
|
||||
let mut file = File::create(path.as_ref()).await?;
|
||||
file.write_all(bytes).await?;
|
||||
Ok(file.sync_data().await?)
|
||||
}
|
||||
|
||||
pub fn read_comm(pid: u32) -> Result<String> {
|
||||
let comm = std::fs::read_to_string(path(format!("/proc/{}/comm", pid)))?;
|
||||
Ok(comm.trim_end().to_string())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue