1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Effective activity paths belong to the observed tree. File facts are lazy
//! and shared by its Snapshot; writer lifetime remains a fresh process check.
use std::path::{Path, PathBuf};
use chrono::{DateTime, Local};
use super::Command;
pub(super) struct Activity {
log: PathBuf,
session: Option<PathBuf>,
now: DateTime<Local>,
}
impl Activity {
pub(super) fn new(log: &Path, session: Option<&Path>, now: DateTime<Local>) -> Self {
Self {
log: log.to_owned(),
session: session.map(crate::logs::session::path),
now,
}
}
}
impl Command {
/// The owning Command log followed by this record's current Session trace.
/// These lexical paths may be outside the Log inventory; no metadata is read.
pub(in crate::logs) fn activity_paths(&self) -> impl Iterator<Item = &Path> {
std::iter::once(self.activity.log.as_path()).chain(self.activity.session.as_deref())
}
/// Stage age bounds quiet age, even when activity metadata is unavailable.
pub(in crate::logs) fn quiet_age(&self) -> u64 {
let stage_age = self
.stage
.as_ref()
.map_or(0, |stage| stage.age_seconds as u64);
self.activity_paths().fold(stage_age, |quiet, path| {
self.inventory
.activity(path)
.modified
.map_or(quiet, |modified| {
quiet.min(
self.activity
.now
.signed_duration_since(DateTime::<Local>::from(modified))
.num_seconds()
.max(0) as u64,
)
})
})
}
/// Lengths share the health sample, with zero for an unavailable file.
pub(in crate::logs) fn activity_lengths(&self) -> (u64, u64) {
(
self.inventory.activity(&self.activity.log).length,
self.activity
.session
.as_deref()
.map_or(0, |path| self.inventory.activity(path).length),
)
}
}