MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / populate_file_index

Method populate_file_index

atomic-repository/src/repository/materialize.rs:828–865  ·  view source on GitHub ↗

Populate the file index for all tracked files after a materialize. Stats each tracked file from disk and stores its mtime + size + content hash in the pristine database. Errors are silently ignored (best-effort). Why we ignore `result.file_results` and walk the tracked set: the `MaterializeResult.file_results` map is only populated when `merge_file_result(_, store_result=true)` is called, and th

(&self, _result: &MaterializeResult)

Source from the content-addressed store, hash-verified

826 /// view's recorded state — every tracked file's on-disk content is
827 /// the authoritative baseline FILE_INDEX should cache.
828 fn populate_file_index(&self, _result: &MaterializeResult) {
829 use std::time::SystemTime;
830
831 let tracked = match self.list_tracked_files() {
832 Ok(t) => t,
833 Err(_) => return,
834 };
835
836 let mut entries: Vec<(String, i64, u32, u64, Hash)> = Vec::with_capacity(tracked.len());
837
838 for file in &tracked {
839 let abs_path = self.root.join(&file.path);
840 let metadata = match std::fs::metadata(&abs_path) {
841 Ok(m) if m.is_file() => m,
842 _ => continue,
843 };
844
845 let mtime = metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH);
846 let duration = mtime
847 .duration_since(SystemTime::UNIX_EPOCH)
848 .unwrap_or_default();
849 let secs = duration.as_secs() as i64;
850 let nanos = duration.subsec_nanos();
851 let size = metadata.len();
852
853 let content_hash = match std::fs::read(&abs_path) {
854 Ok(bytes) => Hash::of(&bytes),
855 Err(_) => continue,
856 };
857
858 let normalized = file.path.to_string_lossy().replace('\\', "/");
859 entries.push((normalized, secs, nanos, size, content_hash));
860 }
861
862 if !entries.is_empty() {
863 let _ = self.update_file_index(&entries);
864 }
865 }
866
867 /// Update FILE_INDEX for a specific set of paths.
868 ///

Callers 2

materialize_prefixMethod · 0.80

Calls 8

list_tracked_filesMethod · 0.80
lenMethod · 0.45
is_fileMethod · 0.45
modifiedMethod · 0.45
replaceMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45
update_file_indexMethod · 0.45

Tested by

no test coverage detected