Repository navigation
Expand file tree
/
Copy pathmodel.rs
More file actions
201 lines (184 loc) · 5.7 KB
/
Copy pathmodel.rs
File metadata and controls
201 lines (184 loc) · 5.7 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
pub const COIN_BYTES: u64 = 100_000_000;
// Rebuild derived findings for category-specific everyday Mac recommendations.
pub const RULE_VERSION: u32 = 12;
pub type Result<T> = std::result::Result<T, String>;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Identity {
pub device: u64,
pub inode: u64,
pub mode: u32,
pub size: u64,
pub modified_ns: i64,
pub changed_ns: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub id: String,
pub path: PathBuf,
pub kind: String,
pub identity: Identity,
}
/// Durable macOS identity used only to renew a grant after device numbering
/// changes. Live traversal and cleanup still use the current device identity.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct RootAnchor {
pub volume_uuid: [u8; 16],
pub birth_seconds: i64,
pub birth_nanoseconds: i64,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum RootAccessStatus {
Available,
ReauthorizationRequired,
Unavailable,
}
#[derive(Debug, Clone, Serialize)]
pub(crate) struct RootAccess {
pub root_id: String,
pub path: PathBuf,
pub status: RootAccessStatus,
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Candidate {
pub id: String,
pub root_id: String,
pub path: PathBuf,
pub title: String,
pub kind: String,
pub logical_bytes: u64,
pub allocated_bytes: u64,
pub file_count: u64,
pub modified_ns: i64,
pub explanation: String,
pub consequence: String,
pub eligible_permanent: bool,
pub blocked_reason: Option<String>,
pub identity: Identity,
pub fingerprint: String,
pub evidence: String,
/// Server-owned recommendation policy. Missing in legacy indexes and Swift
/// review payloads; it never grants mutation permission on its own.
#[serde(default)]
pub suggestion_eligible: bool,
/// In-progress measurement; never replaces a completed cached finding.
#[serde(default)]
pub provisional: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ScanStats {
pub entries: u64,
pub files: u64,
pub directories: u64,
pub logical_bytes: u64,
pub allocated_bytes: u64,
pub skipped: u64,
/// Whole artifact boundaries excluded before their contents were enumerated.
#[serde(default)]
pub excluded_artifacts: u64,
/// Non-candidate names examined without fetching full file metadata.
#[serde(default)]
pub metadata_skipped: u64,
pub errors: u64,
pub candidates: u64,
pub elapsed_ms: u64,
pub first_finding_ms: Option<u64>,
pub cancelled: bool,
pub complete: bool,
pub message: String,
}
/// One finite, explicit Scan request. Background index refreshes have their own
/// worker lifetime and do not change this result after the request finishes.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ForegroundScan {
pub active: bool,
pub stats: ScanStats,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanBatch {
pub candidates: Vec<Candidate>,
pub stats: ScanStats,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Wallet {
pub collected_coins: u64,
pub pending_coins: u64,
pub fractional_bytes: u64,
pub credited_bytes: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Receipt {
pub id: String,
pub path: String,
pub title: String,
pub operation: String,
pub outcome: String,
pub detail: String,
pub created_at: i64,
pub reported_bytes: u64,
pub observed_bytes: u64,
pub credited_bytes: u64,
pub coins: u64,
pub trash_path: Option<String>,
pub can_restore: bool,
/// Ledger position assigned only when a paged history query serves this
/// receipt. Snapshot receipts and stored receipt JSON omit it entirely.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub seq: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Snapshot {
pub roots: Vec<Root>,
pub candidates: Vec<Candidate>,
pub history: Vec<Receipt>,
pub wallet: Wallet,
pub scanning: bool,
pub cleaning: bool,
pub stats: ScanStats,
#[serde(default)]
pub foreground_scan: Option<ForegroundScan>,
pub error: Option<String>,
pub kept_paths: Vec<String>,
}
/// The small, frequently changing part of a native snapshot. Indexed rows and
/// reward/recovery history are deliberately absent from progress-only replies.
#[derive(Debug, Clone, Serialize)]
pub(crate) struct SnapshotProgress {
pub scanning: bool,
pub cleaning: bool,
pub stats: ScanStats,
pub foreground_scan: Option<ForegroundScan>,
pub error: Option<String>,
}
#[derive(Debug, Serialize)]
pub(crate) struct SnapshotUpdate {
pub revision: String,
pub content_revision: String,
pub changed: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub snapshot: Option<Snapshot>,
#[serde(skip_serializing_if = "Option::is_none")]
pub progress: Option<SnapshotProgress>,
}
pub fn now() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
}
pub fn unique_id() -> String {
use std::sync::atomic::{AtomicU64, Ordering};
static NEXT: AtomicU64 = AtomicU64::new(1);
let time = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_nanos();
format!(
"{time:x}-{:x}-{:x}",
std::process::id(),
NEXT.fetch_add(1, Ordering::Relaxed)
)
}