diff --git a/crates/texrra-tex-core/src/resources.rs b/crates/texrra-tex-core/src/resources.rs index 21c573d..944ef6b 100644 --- a/crates/texrra-tex-core/src/resources.rs +++ b/crates/texrra-tex-core/src/resources.rs @@ -636,6 +636,8 @@ pub struct FileWorld { staged_generated: BTreeMap, /// Actual host resource promotions, never inferred from serialized cache. protected_paths: BTreeSet, + // Logical path keys shared by namespace operations within a job. + project_path_keys: OnceLock>, replay_gaps: Vec, project: Option>, system_fonts: Option, String>>, @@ -777,6 +779,7 @@ impl FileWorld { live_paths: BTreeSet::new(), staged_generated: BTreeMap::new(), protected_paths: BTreeSet::new(), + project_path_keys: OnceLock::new(), replay_gaps: Vec::new(), project: None, system_fonts: None, @@ -828,6 +831,7 @@ impl FileWorld { live_paths, staged_generated: BTreeMap::new(), protected_paths: BTreeSet::new(), + project_path_keys: OnceLock::new(), replay_gaps: Vec::new(), project: Some(project), system_fonts: None, @@ -857,7 +861,7 @@ impl FileWorld { pub fn check_generated_output(&self, logical: &Path, physical: &Path) -> Result<(), String> { if let Some(project) = &self.project { self.check_artifact_output(physical)?; - project.check_generated_output(logical, physical, &self.project_paths())?; + project.check_generated_output(logical, physical, self.project_paths())?; } Ok(()) } @@ -866,8 +870,8 @@ impl FileWorld { pub fn generated_output_path(&self, logical: &Path) -> Result { if let Some(project) = &self.project { let known = self.project_paths(); - let target = project.locate(logical, &known)?.path; - project.check_generated_output(logical, &target, &known)?; + let target = project.locate(logical, known)?.path; + project.check_generated_output(logical, &target, known)?; self.check_artifact_output(&target)?; Ok(target) } else { @@ -919,6 +923,7 @@ impl FileWorld { .unwrap_or_default(), staged_generated: BTreeMap::new(), protected_paths: BTreeSet::new(), + project_path_keys: OnceLock::new(), replay_gaps: Vec::new(), project: snapshot.project.clone(), system_fonts: snapshot.system_fonts.clone(), @@ -961,6 +966,7 @@ impl FileWorld { )); } if self.live_paths.insert(path.to_owned()) && self.project.is_some() { + self.project_path_keys.take(); self.current_project_indexes.clear(); } } @@ -986,6 +992,9 @@ impl FileWorld { if self.pinned { if was_live || self.project.is_some() { let newly_protected = self.protected_paths.insert(resource.version.path.clone()); + if was_live || newly_protected { + self.project_path_keys.take(); + } if self.project.as_ref().is_some_and(|project| { was_live || (newly_protected && project.file(&resource.version.path).is_none()) }) { @@ -1063,11 +1072,19 @@ impl FileWorld { pub fn generated_storage<'a>(&'a self, path: &'a Path) -> &'a Path { self.staged_generated.get(path).map_or(path, PathBuf::as_path) } - fn project_paths(&self) -> BTreeSet { - self.live_paths - .union(&self.protected_paths) - .cloned() - .collect() + fn project_paths(&self) -> &BTreeSet { + if self.protected_paths.is_empty() { + &self.live_paths + } else if self.live_paths.is_empty() { + &self.protected_paths + } else { + self.project_path_keys.get_or_init(|| { + self.live_paths + .union(&self.protected_paths) + .cloned() + .collect() + }) + } } fn probe(&mut self, path: &Path) -> Result, String> { // PathBuf equality drops `/.` and trailing separators. Such spellings @@ -1085,7 +1102,7 @@ impl FileWorld { return Self::existing(path); } if let Some(project) = &self.project { - let location = project.locate(path, &self.project_paths())?; + let location = project.locate(path, self.project_paths())?; let result = if location.kind == Some(project::NodeKind::File) { if self.live_paths.contains(&location.path) { if let Some(storage) = self.staged_generated.get(&location.path) { @@ -1454,7 +1471,7 @@ impl FileWorld { || (recursive && !self.indexes[root].recursive) { let index = - project.index(root, &self.project_paths(), self.config.max_index_entries, recursive)?; + project.index(root, self.project_paths(), self.config.max_index_entries, recursive)?; self.indexes.insert(root.into(), Arc::new(index)); self.current_project_indexes.insert(root.into()); } diff --git a/crates/texrra-tex-core/tests/resource_projects.rs b/crates/texrra-tex-core/tests/resource_projects.rs index 450edf0..63327ae 100644 --- a/crates/texrra-tex-core/tests/resource_projects.rs +++ b/crates/texrra-tex-core/tests/resource_projects.rs @@ -447,6 +447,8 @@ fn protected_generated_resources_keep_alias_and_recursive_visibility_without_cac vec![SearchPath::directory(p.join("gen"), true)], ); d.generated.insert(p.join("gen/nested/initial.tfm")); + // Retain a live key while the earlier resource is promoted and the next one is added. + d.generated.insert(p.join("gen/nested/kept-live.tfm")); d.aliases .insert(p.join("again.tfm"), "gen/nested/initial.tfm".into()); d.aliases