diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 06:04:16 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 06:04:16 +0300 |
| commit | 7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa (patch) | |
| tree | c08796dc7a745059701845d735156600202c1b24 /crates | |
| parent | 0d8031eccad92190ea01c2c7f9a2cee28adecb62 (diff) | |
| download | fparkan-7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa.tar.xz fparkan-7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa.zip | |
feat(ui): open saved warbot projects with distinct geometry
Prepare saved Unit DAT geometry alongside factory reserves at mission entry and expose compatible, researched files through the designer. Verified a single-gun assembly in the Field Camp window and after factory release with the ore and power supply established in the test.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 23 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/production.rs | 77 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/robot_designer.rs | 22 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/saved_factory_projects.rs | 285 | ||||
| -rw-r--r-- | crates/fparkan-vfs/src/lib.rs | 63 |
5 files changed, 441 insertions, 29 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index cf9c438f..fa2bfb33 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -146,6 +146,7 @@ mod robot_designer; mod route_motion; mod route_obstacles; mod route_traffic; +mod saved_factory_projects; use resource_distribution::advance_behavior_distributor_tick; mod script_host; mod script_patrol; @@ -198,8 +199,8 @@ pub use player_weapon::{ }; pub use production::{ clan_factory_schemes, factory_part_variants, factory_project_components, factory_project_root, - factory_schemes, order_clan_factory_scheme, order_factory_design, order_factory_robot, - order_factory_scheme, + factory_project_schemes, factory_saved_schemes, factory_schemes, order_clan_factory_scheme, + order_factory_design, order_factory_robot, order_factory_scheme, }; pub use projectile::{ apply_projectile_contact, apply_projectile_hit, apply_projectile_impact, @@ -214,6 +215,7 @@ pub use robot_designer::{ check_factory_design, factory_design_bytes, factory_design_parts, load_gameplay_mission, load_gameplay_mission_with_build_parts, restore_factory_design, FactoryPartChange, }; +pub use saved_factory_projects::is_saved_factory_project_name; pub use unit_combat::{ autonomous_firing_effect_phases, AutoDemoCombatEvent, AutoDemoProjectileType, FiringEffectInstance, @@ -2089,6 +2091,22 @@ fn load_mission_with_options( build_schemes.push(design.path.clone()); } } + let saved_start = build_schemes.len(); + if build_scheme.is_none() + && options.asset_scope == MissionAssetScope::Full + && options.start_autodemo + && request.mode == MissionMode::SingleMission + { + let (source, projects) = saved_factory_projects::prepare( + vfs, + &asset_manager, + &mission, + &build_schemes[..player_scheme_count], + ); + vfs = source; + build_schemes.extend(projects); + } + let saved_schemes = saved_start..build_schemes.len(); let research_trf_tables = if options.asset_scope == MissionAssetScope::Full && startup_input.is_some_and(|input| input.research_creation_gate) { @@ -2802,6 +2820,7 @@ node_provider_distribution_suspended: false, &object_drafts[..construction_reserve_start], )?; production.scheme_vfs = Some(vfs.clone()); + production.saved_schemes = saved_schemes; production }), ) diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs index 3b407467..3502c45d 100644 --- a/crates/fparkan-runtime/src/production.rs +++ b/crates/fparkan-runtime/src/production.rs @@ -34,6 +34,7 @@ pub(super) struct Production { reserve_start: usize, schemes: Vec<NormalizedPath>, player_scheme_count: usize, + pub(super) saved_schemes: std::ops::Range<usize>, customized: bool, pub(super) scheme_vfs: Option<Arc<dyn Vfs>>, ai_schemes: Vec<crate::clan_factory_schemes::ScriptDesign>, @@ -107,6 +108,10 @@ impl PaidOrder { } impl Production { + fn player_project(&self, scheme: usize) -> bool { + scheme < self.player_scheme_count || self.saved_schemes.contains(&scheme) + } + pub(super) fn clock_ticks(&self) -> impl Iterator<Item = (u16, u32, u64)> + '_ { self.clock_ticks .iter() @@ -165,6 +170,7 @@ impl Production { reserve_start, schemes, player_scheme_count, + saved_schemes: 0..0, customized, ai_schemes, controls, @@ -384,9 +390,7 @@ pub fn factory_schemes( ) -> Result<Vec<(usize, &str)>, EngineError> { let (mission, production) = loaded_production(engine)?; let (plant, _) = factory_at_communicator(&engine.world, mission, production, cockpit)?; - Ok(schemes_for_plant(mission, production, plant) - .filter(|&(scheme, _)| scheme < production.player_scheme_count) - .collect()) + Ok(recent_schemes_for_plant(mission, production, plant)) } /// Lists the live factories of the player's clan and matching configured schemes. @@ -398,8 +402,8 @@ pub fn clan_factory_schemes( let owner = player_owner(&engine.world, cockpit)?; Ok(owned_factories(&engine.world, mission, production, owner) .flat_map(|(index, factory, _)| { - schemes_for_plant(mission, production, index) - .filter(|&(scheme, _)| scheme < production.player_scheme_count) + recent_schemes_for_plant(mission, production, index) + .into_iter() .map(move |(scheme, path)| (factory, scheme, path)) }) .collect()) @@ -440,10 +444,64 @@ pub fn factory_part_variants( /// Index of the first prepared world root for a player factory project. pub fn factory_project_root(engine: &Engine, scheme: usize) -> Option<usize> { let (_, production) = loaded_production(engine).ok()?; - (scheme < production.player_scheme_count) + production + .player_project(scheme) .then(|| production.reserve_start + scheme * RESERVE_SLOTS) } +/// Prepared project indices usable by the designer, including saved geometry. +pub fn factory_project_schemes(engine: &Engine) -> impl Iterator<Item = usize> { + let (recent, saved) = loaded_production(engine).map_or((0..0, 0..0), |(_, production)| { + ( + 0..production.player_scheme_count, + production.saved_schemes.clone(), + ) + }); + recent.chain(saved) +} + +/// Saved projects prepared for the current factory. +pub fn factory_saved_schemes( + engine: &Engine, + cockpit: StartingCockpit, + plant: Option<ObjectHandle>, +) -> Result<Vec<usize>, EngineError> { + let (mission, production) = loaded_production(engine)?; + let index = match plant { + Some(plant) => { + let owner = player_owner(&engine.world, cockpit)?; + owned_factories(&engine.world, mission, production, owner) + .find(|&(_, handle, _)| handle == plant) + .map(|(index, _, _)| index) + .ok_or_else(|| { + production_error("selected factory no longer belongs to the player") + })? + } + None => factory_at_communicator(&engine.world, mission, production, cockpit)?.0, + }; + Ok(schemes_for_plant(mission, production, index) + .filter_map(|(scheme, _)| production.saved_schemes.contains(&scheme).then_some(scheme)) + .collect()) +} + +fn recent_schemes_for_plant<'a>( + mission: &'a LoadedMissionState, + production: &'a Production, + plant: usize, +) -> Vec<(usize, &'a str)> { + let mut recent = schemes_for_plant(mission, production, plant) + .filter(|&(scheme, _)| scheme < production.player_scheme_count) + .collect::<Vec<_>>(); + if recent.is_empty() { + recent.extend( + schemes_for_plant(mission, production, plant) + .filter(|&(scheme, _)| production.saved_schemes.contains(&scheme)) + .take(1), + ); + } + recent +} + fn schemes_for_plant<'a>( mission: &'a LoadedMissionState, production: &'a Production, @@ -500,7 +558,7 @@ pub fn order_factory_design( if engine .production .as_ref() - .is_some_and(|production| scheme >= production.player_scheme_count) + .is_some_and(|production| !production.player_project(scheme)) { return Err(production_error("unknown factory scheme")); } @@ -592,7 +650,10 @@ fn order_owned_factory( }) .unwrap_or(&draft.unit_components); let (duration_ms, paid) = if is_free { - if changes.is_empty() && production.customized && scheme == 0 { + if changes.is_empty() + && ((production.customized && scheme == 0) + || production.saved_schemes.contains(&scheme)) + { clan_scheme_cost(&engine.services.vfs, mission, owner, records)?; } (free_ms, None) diff --git a/crates/fparkan-runtime/src/robot_designer.rs b/crates/fparkan-runtime/src/robot_designer.rs index 289881f0..f196f9c1 100644 --- a/crates/fparkan-runtime/src/robot_designer.rs +++ b/crates/fparkan-runtime/src/robot_designer.rs @@ -110,7 +110,7 @@ pub fn restore_factory_design( }) } -fn restore_mounts( +pub(super) fn restore_mounts( base: &[UnitComponentRecord], project: &[UnitComponentRecord], ) -> Option<Vec<FactoryPartChange>> { @@ -429,15 +429,7 @@ pub(super) fn starting_designs( vfs: Arc<dyn Vfs>, mission: &MissionDocument, ) -> (Arc<dyn Vfs>, Vec<NormalizedPath>) { - let mut players = mission - .clans - .iter() - .enumerate() - .filter(|(_, clan)| clan.mode == 1); - let Some(owner) = players.next().filter(|_| players.next().is_none()) else { - return (vfs, Vec::new()); - }; - let Ok(owner) = u16::try_from(owner.0).map(OwnerId) else { + let Some(owner) = mission_player(mission) else { return (vfs, Vec::new()); }; let Ok(research) = crate::research::load_technology_table(vfs.as_ref(), mission, owner) else { @@ -495,6 +487,16 @@ pub(super) fn starting_designs( ) } +pub(super) fn mission_player(mission: &MissionDocument) -> Option<OwnerId> { + let mut players = mission + .clans + .iter() + .enumerate() + .filter(|(_, clan)| clan.mode == 1); + let (index, _) = players.next().filter(|_| players.next().is_none())?; + u16::try_from(index).ok().map(OwnerId) +} + fn adapt_template( mut bytes: Vec<u8>, research: &ResearchTrfDocument, diff --git a/crates/fparkan-runtime/src/saved_factory_projects.rs b/crates/fparkan-runtime/src/saved_factory_projects.rs new file mode 100644 index 00000000..907a45d1 --- /dev/null +++ b/crates/fparkan-runtime/src/saved_factory_projects.rs @@ -0,0 +1,285 @@ +//! Unit DAT files from the local constructor directory. + +use crate::{ + boarding::WARBOT_CLASS, + build_prototype_graph_report, extend_graph_report_with_visual_dependencies, + normalize_engine_path, + production::scheme_cost, + research::load_technology_table, + resource_name, + robot_designer::{mission_player, restore_mounts}, + AssetManager, MissionDocument, ResourceRepository, PROTOTYPE_TYPE_EXTO, +}; +use fparkan_path::NormalizedPath; +use fparkan_prototype::{decode_unit_dat, unit_component_tree}; +use fparkan_vfs::{MemoryVfs, OverlayVfs, Vfs, VfsError}; +use std::sync::Arc; + +/// A named Unit DAT from the original designer directory. +pub fn is_saved_factory_project_name(filename: &str) -> bool { + let lower = filename.to_ascii_lowercase(); + lower.ends_with(".dat") + && !["temp_unit", "bld_unit_", "view_unit_"] + .iter() + .any(|prefix| lower.starts_with(prefix)) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + capture_neutral_building, clan_factory_schemes, create, deploy_mine, + factory_project_components, factory_project_schemes, factory_saved_schemes, frame, + load_gameplay_mission, loaded_mission_object_drafts, order_factory_design, + restore_factory_design, starting_cockpit, EngineServices, MissionMode, MissionRequest, + MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use fparkan_world::{handle_by_original_id, set_transform, transform_state, OriginalObjectId}; + + #[test] + #[ignore = "requires licensed corpus"] + fn field_camp_can_order_a_saved_design_with_other_mounts() { + let corpus = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed root"); + let directory = Arc::new(DirectoryVfs::new(corpus)); + let path = |p| normalize_engine_path("test project", p).unwrap(); + let source = directory + .read(&path("UNITS/UNITS/PREBLD/14swlk.dat")) + .unwrap(); + // Remove the second gun and its internal ammunition slot from the + // original turret's four-child tree. + let mut bytes = source[..8 + 12 * 112].to_vec(); + bytes[8 + 7 * 112 + 108..8 + 8 * 112].copy_from_slice(&3_u32.to_le_bytes()); + let bytes: Arc<[u8]> = bytes.into(); + let mut local = MemoryVfs::default(); + local.insert(path("UNITS/Imported.dat"), bytes.clone()); + local.insert(path("UNITS/ImportedCopy.dat"), bytes.clone()); + local.insert(path("UNITS/Unknown.dat"), Arc::from(&b"truncated"[..])); + let vfs = Arc::new(OverlayVfs::from_layers(vec![Arc::new(local), directory])); + let mut engine = create(EngineServices::new(vfs)).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.03/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + frame(&mut engine, 0).unwrap(); + let cockpit = starting_cockpit(&engine).unwrap(); + let plant = handle_by_original_id(&engine.world, OriginalObjectId(7)).unwrap(); + let recent = clan_factory_schemes(&engine, cockpit).unwrap(); + let recent = recent + .into_iter() + .filter(|&(factory, _, _)| factory == plant) + .map(|(_, scheme, _)| scheme) + .collect::<Vec<_>>(); + assert_eq!(recent.len(), 2); + assert!(restore_factory_design(&engine, cockpit, recent, &bytes).is_none()); + let saved = factory_saved_schemes(&engine, cockpit, Some(plant)).unwrap(); + assert_eq!(saved.len(), 1, "identical geometry shares the reserve"); + let (scheme, changes) = restore_factory_design(&engine, cockpit, saved, &bytes).unwrap(); + assert!(changes.is_empty()); + assert!(factory_project_schemes(&engine).any(|index| index == scheme)); + let expected = decode_unit_dat(&bytes).unwrap().records; + assert_eq!( + factory_project_components(&engine, scheme).unwrap(), + expected + ); + assert_eq!( + order_factory_design(&mut engine, cockpit, Some(plant), scheme, &[], 1).unwrap(), + 5_000 + ); + + // Supply the stock factory using the field camp's two neutral facilities. + let mut pose = transform_state(&engine.world, cockpit.handle).unwrap(); + let handle = handle_by_original_id(&engine.world, OriginalObjectId(0)).unwrap(); + let state = transform_state(&engine.world, handle).unwrap(); + let mission = engine.loaded.as_ref().unwrap(); + let [a, b, c] = crate::mission_events::communicator_triangles( + &mission.mission_assets, + 0, + mission.object_drafts[0].unit_dat_header_flags.unwrap(), + state, + ) + .unwrap()[0]; + pose.position = std::array::from_fn(|axis| ((a[axis] + b[axis] + c[axis]) / 3.0).to_bits()); + set_transform(&mut engine.world, cockpit.handle, pose).unwrap(); + assert_eq!( + capture_neutral_building(&mut engine, cockpit).unwrap(), + Some(OriginalObjectId(0)) + ); + pose.position = [1026.08_f32, 902.706, 81.24426].map(f32::to_bits); + set_transform(&mut engine.world, cockpit.handle, pose).unwrap(); + deploy_mine(&mut engine, cockpit).unwrap(); + pose.position = [659.4_f32, 1050.6, 80.04].map(f32::to_bits); + set_transform(&mut engine.world, cockpit.handle, pose).unwrap(); + assert_eq!( + capture_neutral_building(&mut engine, cockpit).unwrap(), + Some(OriginalObjectId(9)) + ); + let robot = (1..190_100) + .step_by(50) + .find_map(|time| { + let tick = frame(&mut engine, time).unwrap(); + assert!( + tick.production_failure.is_none(), + "{:?}", + tick.production_failure + ); + tick.produced_unit + }) + .expect("the factory released the saved assembly"); + let draft = &loaded_mission_object_drafts(&engine).unwrap()[robot.object_index]; + assert_eq!(draft.unit_components, expected); + } +} + +pub(super) fn prepare<R: ResourceRepository>( + vfs: Arc<dyn Vfs>, + manager: &AssetManager<R>, + mission: &MissionDocument, + existing: &[NormalizedPath], +) -> (Arc<dyn Vfs>, Vec<NormalizedPath>) { + let directory = + normalize_engine_path("saved projects", "UNITS").expect("static project directory"); + let files = match vfs.list_files(&directory) { + Ok(files) => files, + Err(VfsError::NotFound(_)) => return (vfs, Vec::new()), + Err(error) => { + eprintln!("factory_project_directory_unavailable {error}"); + return (vfs, Vec::new()); + } + }; + let mut files = files + .into_iter() + .filter(|path| { + path.as_str() + .rsplit_once('/') + .is_some_and(|(_, name)| is_saved_factory_project_name(name)) + && !existing.contains(path) + }) + .peekable(); + if files.peek().is_none() { + return (vfs, Vec::new()); + } + let Some(owner) = mission_player(mission) else { + return (vfs, Vec::new()); + }; + let Ok(research) = load_technology_table(vfs.as_ref(), mission, owner) else { + return (vfs, Vec::new()); + }; + let mut shapes = existing + .iter() + .filter_map(|path| decode_unit_dat(&vfs.read(path).ok()?).ok()) + .collect::<Vec<_>>(); + let mut snapshot = MemoryVfs::default(); + let mut projects = Vec::new(); + for path in files { + let Ok(bytes) = vfs.read(&path) else { continue }; + let Ok(project) = decode_unit_dat(&bytes) else { + continue; + }; + let mut header = [0; 8]; + header[..4].copy_from_slice(&0xf0f1_u32.to_le_bytes()); + header[4..].copy_from_slice(&WARBOT_CLASS.to_le_bytes()); + // A part may become known during the mission. The designer checks + // actual research again when it lists the file. + if project.header_opaque != header + || scheme_cost(&project.records, &research, |_| true).is_err() + || shapes.iter().any(|base| { + base.header_opaque == header + && restore_mounts(&base.records, &project.records).is_some() + }) + { + continue; + } + let mut candidate = MemoryVfs::default(); + candidate.insert(path.clone(), bytes.clone()); + let source = OverlayVfs::from_layers(vec![Arc::new(candidate), vfs.clone()]); + let (mut graph, prototypes, mut report) = build_prototype_graph_report( + manager.repository(), + &source, + &[resource_name(path.as_bytes())], + ); + extend_graph_report_with_visual_dependencies( + manager.repository(), + &mut report, + &mut graph, + &prototypes, + ); + if !report.is_success() { + eprintln!( + "factory_project_geometry_unavailable path={}", + path.as_str() + ); + continue; + } + let assets = match manager + .prepare_mission_assets(&graph.root_prototype_request_spans, &prototypes) + { + Ok(assets) => assets, + Err(error) => { + eprintln!( + "factory_project_geometry_unavailable path={} {error}", + path.as_str() + ); + continue; + } + }; + let tree = unit_component_tree(&project.records).expect("validated by scheme cost"); + let model_nodes = assets + .visuals_for_object(0) + .iter() + .map(|id| { + assets + .visual_by_id(*id) + .map(|visual| (visual.source_type, visual.model_nodes)) + }) + .collect::<Vec<_>>(); + let mounts_available = model_nodes.len() == project.records.len() + && matches!(model_nodes.first(), Some(Some((_, nodes))) if *nodes != 0) + && model_nodes + .iter() + .enumerate() + .skip(1) + .all(|(index, visual)| { + let Some((kind, nodes)) = visual else { + return false; + }; + if *kind != Some(PROTOTYPE_TYPE_EXTO) { + return true; + } + let Some(parent) = tree[index].parent_index else { + return false; + }; + let Some((parent_kind, parent_nodes)) = model_nodes[parent] else { + return false; + }; + *nodes != 0 + && (parent == 0 || parent_kind == Some(PROTOTYPE_TYPE_EXTO)) + && usize::try_from(project.records[index].parent_or_link) + .is_ok_and(|socket| socket < parent_nodes) + }); + if !mounts_available { + eprintln!("factory_project_mount_unavailable path={}", path.as_str()); + continue; + } + snapshot.insert(path.clone(), bytes); + projects.push(path); + shapes.push(project); + } + if projects.is_empty() { + (vfs, projects) + } else { + ( + Arc::new(OverlayVfs::from_layers(vec![Arc::new(snapshot), vfs])), + projects, + ) + } +} diff --git a/crates/fparkan-vfs/src/lib.rs b/crates/fparkan-vfs/src/lib.rs index 3c92fa17..a2cc3c82 100644 --- a/crates/fparkan-vfs/src/lib.rs +++ b/crates/fparkan-vfs/src/lib.rs @@ -81,6 +81,19 @@ pub trait Vfs: Send + Sync { /// Returns [`VfsError`] when the prefix is invalid, missing, or cannot be /// traversed by the backing store. fn list(&self, prefix: &NormalizedPath) -> Result<Vec<VfsEntry>, VfsError>; + /// Lists regular files immediately inside a directory. + fn list_files(&self, directory: &NormalizedPath) -> Result<Vec<NormalizedPath>, VfsError> { + Ok(self + .list(directory)? + .into_iter() + .map(|entry| entry.path) + .filter(|path| { + path.as_str() + .rsplit_once('/') + .is_some_and(|(parent, _)| parent.eq_ignore_ascii_case(directory.as_str())) + }) + .collect()) + } } /// Host directory VFS. @@ -151,6 +164,18 @@ impl Vfs for DirectoryVfs { entries.sort_by(|a, b| a.path.as_bytes().cmp(b.path.as_bytes())); Ok(entries) } + + fn list_files(&self, directory: &NormalizedPath) -> Result<Vec<NormalizedPath>, VfsError> { + let mut files = Vec::new(); + for entry in fs::read_dir(self.host_path(directory)?).map_err(VfsError::Io)? { + let entry = entry.map_err(VfsError::Io)?; + if entry.file_type().map_err(VfsError::Io)?.is_file() { + files.push(normalize_host_path(&self.root, &entry.path())?); + } + } + files.sort_by(|a, b| a.as_bytes().cmp(b.as_bytes())); + Ok(files) + } } fn resolve_casefolded(root: &Path, normalized: &NormalizedPath) -> Result<PathBuf, VfsError> { @@ -258,22 +283,24 @@ fn list_recursive(root: &Path, dir: &Path, out: &mut Vec<VfsEntry>) -> Result<() if !metadata.is_file() { continue; } - let rel = child.strip_prefix(root).map_err(|_| VfsError::Path)?; - #[cfg(unix)] - let rel_bytes = rel.as_os_str().as_bytes(); - #[cfg(not(unix))] - let rel_bytes = rel.to_str().ok_or(VfsError::Path)?.as_bytes(); - let path = - fparkan_path::normalize_relative(rel_bytes, fparkan_path::PathPolicy::HostCompatible) - .map_err(|_| VfsError::Path)?; out.push(VfsEntry { - path, + path: normalize_host_path(root, &child)?, metadata: metadata_from_host_file(&child, &metadata)?, }); } Ok(()) } +fn normalize_host_path(root: &Path, child: &Path) -> Result<NormalizedPath, VfsError> { + let relative = child.strip_prefix(root).map_err(|_| VfsError::Path)?; + #[cfg(unix)] + let bytes = relative.as_os_str().as_bytes(); + #[cfg(not(unix))] + let bytes = relative.to_str().ok_or(VfsError::Path)?.as_bytes(); + fparkan_path::normalize_relative(bytes, fparkan_path::PathPolicy::HostCompatible) + .map_err(|_| VfsError::Path) +} + fn metadata_from_host_file(path: &Path, metadata: &fs::Metadata) -> Result<VfsMetadata, VfsError> { if !metadata.is_file() { return Err(VfsError::Path); @@ -486,6 +513,24 @@ impl Vfs for OverlayVfs { entries.sort_by(|a, b| a.path.as_bytes().cmp(b.path.as_bytes())); Ok(entries) } + + fn list_files(&self, directory: &NormalizedPath) -> Result<Vec<NormalizedPath>, VfsError> { + let mut names = BTreeMap::new(); + for layer in &self.layers { + match layer.list_files(directory) { + Ok(files) => { + for path in files { + names + .entry(ascii_lookup_key(path.as_bytes()).0) + .or_insert(path); + } + } + Err(VfsError::NotFound(_)) => {} + Err(error) => return Err(error), + } + } + Ok(names.into_values().collect()) + } } #[cfg(test)] |
