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

Function update_content_index_paths

atomic-repository/src/content_search.rs:116–173  ·  view source on GitHub ↗

Incrementally refresh the content index for a set of repo-relative paths that changed (e.g. the files touched by a recorded change) and persist the result to disk. Each path is re-read from disk: added/modified files are re-indexed and deleted files are removed, keeping the index in sync with the working copy without re-walking the whole tree. Ignored and Atomic-internal paths are skipped so buil

(
    repo_root: &Path,
    paths: I,
)

Source from the content-addressed store, hash-verified

114/// No-op when the content index does not yet exist — building it is the job of
115/// [`build_content_index`]; this only maintains an existing index.
116pub fn update_content_index_paths<I, P>(
117 repo_root: &Path,
118 paths: I,
119) -> Result<(), ContentSearchError>
120where
121 I: IntoIterator<Item = P>,
122 P: AsRef<Path>,
123{
124 if !has_content_index(repo_root) {
125 return Ok(());
126 }
127
128 // The open + compact below race syntext's own lock-downgrade windows and
129 // any concurrent reader/writer on the same index dir, so retry the whole
130 // update on a lock conflict rather than treating it as a hard failure.
131 // Collect the paths once: the retry closure may run multiple times.
132 let paths: Vec<std::path::PathBuf> = paths
133 .into_iter()
134 .map(|p| p.as_ref().to_path_buf())
135 .collect();
136 with_lock_retry(|| {
137 let ignore_rules = crate::ignore::IgnoreRules::load_for_enrichment(repo_root);
138 let config = content_config(repo_root);
139 let index = Index::open(config)?;
140
141 let mut any = false;
142 for path in &paths {
143 let rel = path.as_path();
144 if crate::ignore::is_enrichment_internal(rel) || ignore_rules.is_ignored(rel, false) {
145 continue;
146 }
147 // syntext strips `repo_root` to derive the relative path, so hand it an
148 // absolute path. The file need not exist — a missing file is treated as
149 // a deletion and removed from the index.
150 let absolute = repo_root.join(rel);
151 index.notify_change(&absolute)?;
152 any = true;
153 }
154
155 if !any {
156 return Ok(());
157 }
158
159 // Commit the pending overlay and fold it into on-disk base segments so the
160 // change survives to the next `Index::open`. When the changed set is large
161 // relative to the index (syntext caps the overlay at 50% of base docs),
162 // `compact` reports `OverlayFull`; the sanctioned recovery is a full
163 // (filtered) rebuild.
164 match index.compact() {
165 Ok(()) => Ok(()),
166 Err(IndexError::OverlayFull { .. }) => {
167 drop(index);
168 build_content_index(repo_root)
169 }
170 Err(e) => Err(e.into()),
171 }
172 })
173}

Callers 3

enrich_changeMethod · 0.85
record_with_lifecycleMethod · 0.85

Calls 10

has_content_indexFunction · 0.85
with_lock_retryFunction · 0.85
content_configFunction · 0.85
openFunction · 0.85
is_enrichment_internalFunction · 0.85
build_content_indexFunction · 0.85
as_refMethod · 0.80
collectMethod · 0.45
into_iterMethod · 0.45
is_ignoredMethod · 0.45