Cheap directory fingerprint: a rolling sum of file mtimes and sizes.
(dir: &Path)
| 107 | |
| 108 | /// Cheap directory fingerprint: a rolling sum of file mtimes and sizes. |
| 109 | fn fingerprint(dir: &Path) -> u64 { |
| 110 | fn walk(dir: &Path, acc: &mut u64) { |
| 111 | let Ok(entries) = std::fs::read_dir(dir) else { return }; |
| 112 | for entry in entries.flatten() { |
| 113 | let path = entry.path(); |
| 114 | if path.is_dir() { |
| 115 | walk(&path, acc); |
| 116 | } else if let Ok(meta) = entry.metadata() { |
| 117 | let mtime = meta |
| 118 | .modified() |
| 119 | .ok() |
| 120 | .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) |
| 121 | .map(|d| d.as_secs()) |
| 122 | .unwrap_or(0); |
| 123 | *acc = acc.wrapping_add(mtime).wrapping_add(meta.len()); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | let mut acc = 0; |
| 128 | walk(dir, &mut acc); |
| 129 | acc |
| 130 | } |
| 131 | |
| 132 | #[cfg(target_os = "macos")] |
| 133 | fn open_url(url: &str) -> std::io::Result<()> { |