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

Method populate_file_index

atomic-repository/src/repository/materialize.rs:582–619  ·  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

580 /// view's recorded state — every tracked file's on-disk content is
581 /// the authoritative baseline FILE_INDEX should cache.
582 fn populate_file_index(&self, _result: &MaterializeResult) {
583 use std::time::SystemTime;
584
585 let tracked = match self.list_tracked_files() {
586 Ok(t) => t,
587 Err(_) => return,
588 };
589
590 let mut entries: Vec<(String, i64, u32, u64, Hash)> = Vec::with_capacity(tracked.len());
591
592 for file in &tracked {
593 let abs_path = self.root.join(&file.path);
594 let metadata = match std::fs::metadata(&abs_path) {
595 Ok(m) if m.is_file() => m,
596 _ => continue,
597 };
598
599 let mtime = metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH);
600 let duration = mtime
601 .duration_since(SystemTime::UNIX_EPOCH)
602 .unwrap_or_default();
603 let secs = duration.as_secs() as i64;
604 let nanos = duration.subsec_nanos();
605 let size = metadata.len();
606
607 let content_hash = match std::fs::read(&abs_path) {
608 Ok(bytes) => Hash::of(&bytes),
609 Err(_) => continue,
610 };
611
612 let normalized = file.path.to_string_lossy().replace('\\', "/");
613 entries.push((normalized, secs, nanos, size, content_hash));
614 }
615
616 if !entries.is_empty() {
617 let _ = self.update_file_index(&entries);
618 }
619 }
620
621 /// Update FILE_INDEX for a specific set of paths.
622 ///

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