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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
pub type Stage = u32;
mod mode;
pub use mode::Mode;
mod flags;
pub(crate) use flags::at_rest;
pub use flags::Flags;
mod write;
#[derive(Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Time {
pub secs: u32,
pub nsecs: u32,
}
#[derive(Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Stat {
pub mtime: Time,
pub ctime: Time,
pub dev: u32,
pub ino: u32,
pub uid: u32,
pub gid: u32,
pub size: u32,
}
mod access {
use bstr::{BStr, ByteSlice};
use crate::{entry, Entry, State};
impl Entry {
pub fn path<'a>(&self, state: &'a State) -> &'a BStr {
state.path_backing[self.path.clone()].as_bstr()
}
pub fn path_in<'backing>(&self, backing: &'backing crate::PathStorageRef) -> &'backing BStr {
backing[self.path.clone()].as_bstr()
}
pub fn stage(&self) -> entry::Stage {
self.flags.stage()
}
}
}
mod _impls {
use std::{cmp::Ordering, ops::Add, time::SystemTime};
use bstr::BStr;
use crate::{entry::Time, Entry, State};
impl From<SystemTime> for Time {
fn from(s: SystemTime) -> Self {
let d = s
.duration_since(std::time::UNIX_EPOCH)
.expect("system time is not before unix epoch!");
Time {
secs: d.as_secs() as u32,
nsecs: d.subsec_nanos(),
}
}
}
impl From<Time> for SystemTime {
fn from(s: Time) -> Self {
std::time::UNIX_EPOCH.add(std::time::Duration::new(s.secs.into(), s.nsecs))
}
}
impl Entry {
pub fn cmp(&self, other: &Self, state: &State) -> Ordering {
let lhs = self.path(state);
let rhs = other.path(state);
Entry::cmp_filepaths(lhs, rhs).then_with(|| self.stage().cmp(&other.stage()))
}
pub fn cmp_filepaths(a: &BStr, b: &BStr) -> Ordering {
let common_len = a.len().min(b.len());
a[..common_len]
.cmp(&b[..common_len])
.then_with(|| a.len().cmp(&b.len()))
}
}
}