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
//! What:
//! The record of one judged reference lock, and the outcome of one clearing pass.
//! Why:
//! The callers decide what to do from the outcome (run the command again only when a lock was cleared) and the notice is
//! worded from the same record, so what was printed is what was decided.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! type Outcome = { cleared: Found[]; left: Found[]; displaced: string[] };
//! ```
use super::stale_ref_lock_judge::Verdict;
use std::path::PathBuf;
use std::time::SystemTime;
/// What the pid file beside a lock says.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PidFile {
/// No pid file, or one that holds no readable number yet.
Absent,
/// A pid file born before the lock: written by an earlier holder, so it names nobody who holds this lock.
Older(i64),
/// A pid file born at or after the lock, naming this process.
Names(i64),
}
/// One judged reference lock.
#[derive(Clone, Debug)]
pub struct Found {
/// The lock file.
pub lock: PathBuf,
/// What the judgement concluded.
pub verdict: Verdict,
/// The size of the lock when it was judged.
pub size: u64,
/// When the lock was born, where the file system keeps it.
pub born: Option<SystemTime>,
/// The pid file beside the lock.
pub pid_file: PidFile,
/// The files that go with the lock and are removed or named with it: its pid file and, for `packed-refs.lock`, the
/// staging file `packed-refs.new`. Only those that exist.
pub companions: Vec<PathBuf>,
}
/// The result of one clearing pass.
#[derive(Clone, Debug, Default)]
pub struct Outcome {
/// Locks that were removed.
pub cleared: Vec<Found>,
/// Locks that were left alone, with the reason each was not removed.
pub left: Vec<Found>,
/// Files that were set aside and could not be put back or removed because the path had been taken again.
pub displaced: Vec<PathBuf>,
}
impl Outcome {
/// Whether a lock was removed, which is the one reason to run the blocked command again.
pub fn cleared_any(&self) -> bool {
return !self.cleared.is_empty();
}
}