style: rustfmt

This commit is contained in:
l0ng-ai
2026-08-08 10:58:26 +08:00
parent 0f237a766a
commit ad285bcaa1
2 changed files with 12 additions and 10 deletions
+8 -9
View File
@@ -95,10 +95,13 @@ pub(crate) fn held() -> bool {
let Ok(contents) = std::fs::read_to_string(&path) else {
return false;
};
let written = std::fs::metadata(&path).and_then(|meta| meta.modified()).ok();
let holds = contents.trim().parse::<u32>().ok().is_some_and(|pid| {
writer_holds(process_alive(pid), winproc::creation_time(pid), written)
});
let written = std::fs::metadata(&path)
.and_then(|meta| meta.modified())
.ok();
let holds =
contents.trim().parse::<u32>().ok().is_some_and(|pid| {
writer_holds(process_alive(pid), winproc::creation_time(pid), written)
});
if !holds {
log::info!("removing a stale update guard at {}", path.display());
let _ = std::fs::remove_file(&path);
@@ -108,11 +111,7 @@ pub(crate) fn held() -> bool {
/// The staleness policy, pure so every case is testable: `started` is when
/// the process wearing the recorded pid began, `written` the guard's mtime.
fn writer_holds(
alive: bool,
started: Option<SystemTime>,
written: Option<SystemTime>,
) -> bool {
fn writer_holds(alive: bool, started: Option<SystemTime>, written: Option<SystemTime>) -> bool {
if !alive {
return false;
}
+4 -1
View File
@@ -143,7 +143,10 @@ pub(crate) fn creation_time(pid: u32) -> Option<std::time::SystemTime> {
let unix_ticks = ticks.checked_sub(11_644_473_600 * 10_000_000)?;
Some(
std::time::UNIX_EPOCH
+ std::time::Duration::new(unix_ticks / 10_000_000, (unix_ticks % 10_000_000) as u32 * 100),
+ std::time::Duration::new(
unix_ticks / 10_000_000,
(unix_ticks % 10_000_000) as u32 * 100,
),
)
}
}