pacenotes_installer\ledger/
ownership.rs1impl super::Ledger {
2 pub fn is_empty(&self) -> bool {
3 self.document.packages.is_empty()
4 }
5
6 pub fn len(&self) -> usize {
7 self.document.packages.len()
8 }
9
10 pub fn packages(&self) -> &std::collections::BTreeMap<String, super::LedgerEntry> {
12 &self.document.packages
13 }
14
15 pub fn get(&self, key: &str) -> Option<&super::LedgerEntry> {
16 self.document.packages.get(key)
17 }
18
19 pub fn unfinished(&self) -> Vec<String> {
21 self.document
22 .packages
23 .iter()
24 .filter(|(_, entry)| entry.state == super::EntryState::Installing)
25 .map(|(key, _)| key.clone())
26 .collect()
27 }
28
29 pub fn owners_of(&self, path: &str) -> Vec<&str> {
31 let key = fold(path);
32 self.document
33 .packages
34 .iter()
35 .filter(|(_, entry)| entry.files.contains_key(&key))
36 .map(|(package, _)| package.as_str())
37 .collect()
38 }
39
40 pub fn owns(&self, path: &str) -> bool {
42 !self.owners_of(path).is_empty()
43 }
44}
45
46pub fn fold(path: &str) -> String {
49 path.to_lowercase()
50}