From 9b1c1e3ff123f83ecb6b7987103739b561a10bcc Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 04:24:22 -0600 Subject: [PATCH 1/7] fix(project): keep a layer held to the internet when its project is opened again A layer whose addresses came from a document read from the internet is held there for the session, but the hold wasn't saved: opened again in a new session, the layer was read as if the user had named its addresses. Tile layers and map layers now save an optional internetOnly mark from the session's record, and reading a project, map file or layer file holds a marked layer's addresses to the internet again before anything is read. The mark only narrows; a layer without it is read as before. --- crates/engine/src/cmd/items.rs | 7 +- crates/engine/src/project.rs | 178 +++++++++++++++++++++++++++++ crates/map/src/lib.rs | 8 ++ crates/map/src/look.rs | 3 + crates/map/src/tiles.rs | 13 +++ crates/tiles/src/cache.rs | 12 ++ schema/fixtures/internet_only.rgis | 103 +++++++++++++++++ 7 files changed, 322 insertions(+), 2 deletions(-) create mode 100644 schema/fixtures/internet_only.rgis diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index 45ce47278f..ba0f7009ec 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -1829,7 +1829,9 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve "map" => { let map = saved_map(s, p)?; crate::project::ensure_map_imports_complete(map)?; - let map = embedded_map(map, &mut MAX_EMBED.clone()); + let mut map = embedded_map(map, &mut MAX_EMBED.clone()); + // What documents read from the internet named stays held there when the file is read. + crate::project::mark_internet_only(&mut map); let name = map.name.clone(); (name, durable_bytes_with(s, map, crate::project::map_file_bytes)?) } @@ -1839,7 +1841,8 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve if l.dataset.source.as_deref().is_some_and(|source| source.starts_with("geolibre-pending:")) { return Err("this layer is still downloading; wait for it to finish before saving".into()); } - let layer = embed_layer(l, &mut MAX_EMBED.clone()); + let mut layer = embed_layer(l, &mut MAX_EMBED.clone()); + crate::project::mark_layer_internet_only(&mut layer); let name = layer.name.clone(); (name, durable_bytes_with(s, layer, crate::project::layer_file_bytes)?) } diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 43c54b04eb..04e9e42bc0 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1711,6 +1711,9 @@ impl Project { false } }); + // Layers whose addresses a document read from the internet named are held there again, + // before anything below is read (a raster in place, a streamed source). + apply_internet_only(m); // GeoTIFFs read in place are raster layers (a project from before saved tile layers), // so they don't count toward the tile layers kept. As the project opens only: a tile // layer added this session stays one until the project is opened again. @@ -1855,10 +1858,18 @@ impl Project { } } + /// Marks every map's layers held to the internet ([`mark_internet_only`]), before writing. + pub(crate) fn mark_internet_only(&mut self) { + for map in self.maps.iter_mut().chain(self.offline_areas.iter_mut().map(|area| &mut area.data)) { + mark_internet_only(map); + } + } + /// Writes controlled durable fields and relative paths in one guarded transaction. Live /// fields are restored on every return and native unwind; only explicit saves are remembered. pub fn saved_text(&mut self, dir: Option<&Path>) -> Result<(String, crate::durable::Report), String> { self.ensure_imports_complete()?; + self.mark_internet_only(); let unrecorded = self.bound_address_losses(false); let (text, mut report) = crate::durable::output_remembered(self, dir.and_then(Path::to_str), project_text)?; report.addresses = report.addresses.saturating_add(u32::try_from(unrecorded).unwrap_or(u32::MAX)); @@ -1881,6 +1892,7 @@ impl Project { /// Text too large to open again is refused. Returns the text and its counted output notices. pub fn recovery_text_with_report(mut self) -> Result<(String, crate::durable::Report), String> { self.omit_pending_imports(); + self.mark_internet_only(); let unrecorded = self.bound_address_losses(false); // Refused as a recovery copy, not as a save, and never built past the limit. let (text, mut report) = crate::durable::output_owned(self, |p| { @@ -2942,6 +2954,70 @@ impl Durable for ModelGraph { } /// Enforces the opening bound inside the formatter, before any destination is replaced. +/// Marks, before a map is written, each layer whose addresses this session recorded as named by a +/// document read from the internet ([`cache::recorded_public`]), so the restriction is saved with +/// it (`internetOnly`) and [`apply_internet_only`] puts it back when the map is read again. Only +/// ever sets the mark: a layer marked once stays held to the internet. +/// +/// [`cache::recorded_public`]: crate::render::rustgis_tiles::cache::recorded_public +pub(crate) fn mark_internet_only(map: &mut Map) { + use crate::render::rustgis_tiles::cache; + for tile in &mut map.tiles { + tile.internet_only |= cache::recorded_public(&tile.url); + } + for layer in &mut map.layers { + mark_layer_internet_only(layer); + } +} + +/// [`mark_internet_only`] for one layer: marked when an address its source is read again from was +/// recorded as named by a document read from the internet. +pub(crate) fn mark_layer_internet_only(layer: &mut rustgis_map::Layer) { + use crate::render::rustgis_tiles::cache; + let recorded = layer_web_addresses(layer).any(cache::recorded_public); + layer.internet_only |= recorded; +} + +/// The web addresses a layer's source is read again from (local paths left out). +fn layer_web_addresses(layer: &rustgis_map::Layer) -> impl Iterator { + layer.output_slots().into_iter().filter(|(_, v, _, local)| !local && rustgis_map::tiles::is_web(v)).map(|(_, v, _, _)| v) +} + +/// Holds the addresses of every layer of `map` marked `internetOnly` to the internet +/// ([`cache::restrict_to_public`]), as when they were added: a project or map file read again keeps +/// what its documents named on the internet, however their names resolve now. The mark comes from +/// the file, which is untrusted input, and can only narrow what a layer reaches; a layer without +/// it is read as before. Per layer it records its template, dated steps and legends (a tile layer: +/// at most 1 + [`MAX_TIME_URLS`](rustgis_map::tiles::MAX_TIME_URLS) + 16), or its source addresses +/// and a Shapefile's parts (a map layer: at most 3 + 4). +/// +/// [`cache::restrict_to_public`]: crate::render::rustgis_tiles::cache::restrict_to_public +pub(crate) fn apply_internet_only(map: &Map) { + use crate::render::rustgis_tiles::cache; + for tile in map.tiles.iter().filter(|t| t.internet_only) { + for address in tile.addresses().filter(|a| rustgis_map::tiles::is_web(a)) { + cache::restrict_to_public(address); + } + } + for layer in map.layers.iter().filter(|l| l.internet_only) { + apply_layer_internet_only(layer); + } +} + +/// [`apply_internet_only`] for one layer. +fn apply_layer_internet_only(layer: &rustgis_map::Layer) { + use crate::render::rustgis_tiles::cache; + if !layer.internet_only { + return; + } + for address in layer_web_addresses(layer) { + cache::restrict_to_public(address); + for (_, part) in rustgis_data::io::shapefile_part_urls(address).unwrap_or_default() { + cache::restrict_to_public(&part); + } + } +} + fn project_text(p: &Project) -> Result { let max = max_bytes(); json_within(p, max)?.ok_or_else(|| format!("the project is too large to save (maximum {})", limit_said(max))) @@ -2972,6 +3048,108 @@ mod requires_tests { } } +#[cfg(all(test, not(target_arch = "wasm32")))] +mod internet_only_tests { + use crate::render::rustgis_tiles::{address::Reach, cache}; + use crate::{Project, Session}; + use serde_json::json; + + /// The session's record of what each address may reach, as a new process has it: nothing + /// recorded. ([`cache::clear_public_restrictions`] would clear other tests' records too.) + fn forget(addresses: &[&str]) { + for a in addresses { + cache::allow_named(a); + } + } + + /// A layer added from a document read from the internet keeps that after the project is saved + /// and opened again in a new session: its tiles, legend, style and features are fetched only + /// from the internet. The same project without the mark (one an older RustGIS saved) opens as + /// before, and a mark can't widen what an address already reaches. + #[test] + fn what_documents_from_the_internet_named_stays_there_when_the_project_is_opened_again() { + let host = "saved-reach.example"; + let wms = format!("https://{host}/wms"); + let legend = format!("https://{host}/legend.png"); + let style = format!("https://{host}/styles/roads.json"); + let features = format!("https://{host}/collections/roads/items.fgb"); + // The capabilities were read from the internet (the app's record of them). + cache::restrict_to_public(&rustgis_data::ogc::capabilities_url(&wms, Some("wms"))); + let caps = format!( + r#" +Test WMS +image/png +RootEPSG:3857roadsRoads + +"# + ); + let mut s = Session::new(Project::default()); + s.run("service.add", &json!({"url": wms, "type": "wms", "layer": "roads", "text": caps})).unwrap(); + // A style and a features source a document read from the internet named. + s.run("map.addTiles", &json!({"url": style, "name": "Roads style", "kind": "style"})).unwrap(); + cache::restrict_to_public(&style); + let roads = r#"{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"n":1},"geometry":{"type":"Point","coordinates":[8.5,47.4]}}]}"#; + s.run("layer.addDataText", &json!({"fileName": "roads.geojson", "text": roads})).unwrap(); + let id = s.map().layers.last().map(|l| l.id).unwrap(); + s.map_mut().layer_mut(id).unwrap().dataset.source = Some(features.clone()); + cache::restrict_to_public(&features); + let template = s.map().tiles.iter().find(|t| t.name == "Roads").map(|t| t.url.clone()).unwrap(); + let addresses = [template.as_str(), legend.as_str(), style.as_str(), features.as_str()]; + for a in addresses { + assert_eq!(cache::ceiling_for(a), Reach::Public, "{a}, as added"); + } + let (saved, _) = s.project.saved_text(None).unwrap(); + let ceilings = |text: &str| { + forget(&addresses); + let s = Session::new(Project::from_json(text).unwrap()); + let marked = + s.map().tiles.iter().filter(|t| t.internet_only).count() + s.map().layers.iter().filter(|l| l.internet_only).count(); + (addresses.map(cache::ceiling_for), marked) + }; + assert_eq!(ceilings(&saved), ([Reach::Public; 4], 3), "opened again in a new session"); + // An older RustGIS's project, without the mark: as before, the user's own. + let mut older: serde_json::Value = serde_json::from_str(&saved).unwrap(); + let mut dropped = 0; + for map in older["maps"].as_array_mut().unwrap() { + // (A tile layer's keys are camel case, a map layer's snake case.) + for (part, key) in [("tiles", "internetOnly"), ("layers", "internet_only")] { + for item in map[part].as_array_mut().into_iter().flatten() { + dropped += usize::from(item.as_object_mut().unwrap().remove(key).is_some()); + } + } + } + assert_eq!(dropped, 3); + assert_eq!(ceilings(&older.to_string()), ([Reach::Local; 4], 0), "a project without the mark"); + // The mark only narrows: an address held to the internet stays held in a project without it. + cache::restrict_to_public(&template); + let s = Session::new(Project::from_json(&older.to_string()).unwrap()); + assert_eq!(cache::ceiling_for(&template), Reach::Public); + drop(s); + } + + /// The fixture project's marked WMS layer opens with its template and legend held to the + /// internet; without the mark, they are the user's own. + #[test] + fn the_fixture_projects_marked_layer_opens_held_to_the_internet() { + let text = include_str!("../../../schema/fixtures/internet_only.rgis"); + let project = Project::from_json(text).unwrap(); + let tile = &project.maps[0].tiles[0]; + assert!(tile.internet_only); + let addresses: Vec = tile.addresses().map(str::to_string).collect(); + let addresses: Vec<&str> = addresses.iter().map(String::as_str).collect(); + assert_eq!(addresses.len(), 2, "{addresses:?}"); + for (text, want) in + [(text.replace("\"internetOnly\": true", "\"internetOnly\": false"), Reach::Local), (text.to_string(), Reach::Public)] + { + forget(&addresses); + let _s = Session::new(Project::from_json(&text).unwrap()); + for a in &addresses { + assert_eq!(cache::ceiling_for(a), want, "{a}"); + } + } + } +} + #[cfg(test)] mod limit_tests { use super::*; diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index d54e0f5209..6d6479f47f 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -316,6 +316,12 @@ pub struct Layer { /// after saving and reopening the project. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub anonymous: bool, + /// Its source's addresses came from a document read from the internet, so they are read only + /// from there, including after the project is saved and opened again (the session's record of + /// where documents were read isn't saved). It only ever narrows what the layer reaches; + /// without it, a layer is read as before. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub internet_only: bool, /// Process-local identity, preserved by snapshots but never stored in a project. #[serde(skip, default = "next_layer_instance")] instance_id: u64, @@ -572,6 +578,7 @@ impl Layer { synced: None, connection: String::new(), anonymous: false, + internet_only: false, projected: Default::default(), display: None, display_rejected: Vec::new(), @@ -3741,6 +3748,7 @@ impl Layer { synced: _, connection: _, anonymous: _, + internet_only: _, instance_id: _, projected: _, display: _, diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 2830323574..7bed51a635 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -83,6 +83,7 @@ fn bare(layer: &Layer) -> Layer { synced: _, connection, anonymous, + internet_only, instance_id, replacement_rev, // Caches, emptied below. @@ -160,6 +161,7 @@ fn bare(layer: &Layer) -> Layer { synced: None, connection: connection.clone(), anonymous: *anonymous, + internet_only: *internet_only, instance_id: *instance_id, replacement_rev: *replacement_rev, projected: projected.clone(), @@ -256,6 +258,7 @@ impl LayerLook { synced: _, connection: _, anonymous: _, + internet_only: _, instance_id, replacement_rev, // Caches worked out from the rows, which are compared themselves. diff --git a/crates/map/src/tiles.rs b/crates/map/src/tiles.rs index 914d9f196a..0783445c5d 100644 --- a/crates/map/src/tiles.rs +++ b/crates/map/src/tiles.rs @@ -188,6 +188,12 @@ pub struct TileLayer { /// web-service login, including after saving and reopening the project. #[serde(default, skip_serializing_if = "is_false")] pub anonymous: bool, + /// Its addresses (template, legends, dated steps) came from a document read from the internet, + /// so they are fetched only from there, including after the project is saved and opened again + /// (the session's record of where documents were read isn't saved). It only ever narrows what + /// the layer reaches; without it, a layer is read as before. + #[serde(default, skip_serializing_if = "is_false")] + pub internet_only: bool, /// Picked in the Layers pane (`map.selectTiles`), for the session only: it holds while no /// map layer is active (the engine's `Session::selected_tile`). #[serde(skip)] @@ -416,6 +422,7 @@ impl TileLayer { legends: Vec::new(), connection: String::new(), anonymous: false, + internet_only: false, expanded: false, selected: false, single_image: false, @@ -710,6 +717,7 @@ impl TileLayer { legends, connection: _, anonymous: _, + internet_only: _, expanded: _, selected: _, single_image: _, @@ -729,6 +737,11 @@ impl TileLayer { out } + /// Every address the layer keeps and fetches from: its template, dated steps and legends. + pub fn addresses(&self) -> impl Iterator { + self.output_slots().into_iter().map(|(_, address, _)| address) + } + /// Resolves a fixed location, independent of the address's current spelling. pub(crate) fn output_slot_mut(&mut self, role: crate::TileRole) -> Option<&mut String> { match role { diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index c83f7551be..38038e9c28 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -605,6 +605,18 @@ pub fn ceiling_for(url: &str) -> crate::address::Reach { } } +/// Whether [`restrict_to_public`] recorded `url` itself (or a template it matches), so a document +/// read from the internet named it. Unlike [`ceiling_for`], a full table doesn't make this true: +/// what is saved with a project must say what was recorded, not that the table filled up. +pub fn recorded_public(url: &str) -> bool { + let base = canonical_resource(url); + if base.is_empty() { + return false; + } + let p = public_only().lock().unwrap_or_else(|e| e.into_inner()); + p.exact.contains(base) || (!p.named_local.contains(base) && p.templates.iter().any(|tpl| tpl.matches(base))) +} + /// Resets document-origin public restrictions recorded by [`restrict_to_public`] and [`allow_named`]. pub fn clear_public_restrictions() { let mut p = public_only().lock().unwrap_or_else(|e| e.into_inner()); diff --git a/schema/fixtures/internet_only.rgis b/schema/fixtures/internet_only.rgis new file mode 100644 index 0000000000..5457be9922 --- /dev/null +++ b/schema/fixtures/internet_only.rgis @@ -0,0 +1,103 @@ +{ + "format": 2, + "name": "Internet only", + "maps": [ + { + "name": "Map", + "layers": [], + "basemap": "Paper", + "camera": { + "center": { + "x": 0.0, + "y": 2000000.0 + }, + "res": 30000.0, + "bearing": 0.0, + "pitch": 0.0 + }, + "bookmarks": [], + "graticule": true, + "projection": "WebMercator", + "popup_mode": "Topmost", + "label_display": { + "paused": false, + "locked": false, + "show_unplaced": false + }, + "editing": { + "relationships": [], + "snapping": { + "enabled": false, + "tolerance_px": 10.0, + "vertex": true, + "edge": true, + "end": true + }, + "topology": [], + "settings": { + "enabled": true, + "show_vertices": true, + "elevation": "None", + "ground_to_grid": null + } + }, + "swipe": null, + "view": { + "effects": { + "stars": true, + "sun_time": null, + "weather": "None", + "vignette": false, + "edges": false, + "tilt_shift": false, + "grain": false, + "brightness": 0.0, + "contrast": 0.0, + "saturation": 0.0, + "sepia": 0.0 + }, + "wireframe": false, + "clip_distance": null + }, + "animation": [], + "next_layer_id": 1, + "tiles": [ + { + "name": "Roads", + "kind": "raster", + "url": "https://internet-only-fixture.example/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=roads&STYLES=&CRS=EPSG:3857&BBOX={bbox-epsg-3857}&WIDTH=256&HEIGHT=256&FORMAT=image/png", + "legends": [ + { + "url": "https://internet-only-fixture.example/legend.png" + } + ], + "internetOnly": true + } + ] + } + ], + "active_map": 0, + "tables": [], + "next_table_id": 1, + "gp_history": [], + "layouts": [], + "folders": [], + "styles": [], + "ramps": [], + "tasks": [], + "gp_env": { + "extent": null, + "cell_size": null + }, + "models": [], + "workspaces": [], + "link_views": false, + "jobs": [], + "offline_areas": [], + "reports": [], + "presentations": [], + "notebooks": [], + "dl_models": [], + "shared": [], + "data_stores": [] +} From 531506b22ce5c637b1754f8fa7b2675260e9dafa Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 09:32:59 -0600 Subject: [PATCH 2/7] fix(project): require internet-only for held layers; hold offline maps and packages too A file with a layer held to the internet now lists internet-only in requires, so an older RustGIS refuses it by name instead of saving it again without the hold. Opening an offline area as a map holds its marked layers again, project and map packages carry the mark, and only the tile layers a project keeps are held when it is read. --- crates/engine/src/cmd/items.rs | 3 + crates/engine/src/cmd/workspace.rs | 3 + crates/engine/src/project.rs | 112 ++++++++++++++++++++-- crates/engine/src/project_capabilities.rs | 6 ++ docs/maintaining.md | 5 + schema/fixtures/internet_only.rgis | 3 + schema/project.schema.json | 6 +- 7 files changed, 127 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index ba0f7009ec..b51616455a 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -846,6 +846,8 @@ fn package_project(s: &mut Session, notes: &mut rustgis_data::loss::Notes) -> Re } // Offline areas are maps too, and their copies keep a streamed layer's source and the tiles. let linked = left_linked("Package Project", p.maps.iter().chain(p.offline_areas.iter().map(|a| &a.data))); + // What documents read from the internet named stays held there when the package is read. + p.mark_internet_only(); let name = p.name.clone(); let readme = format!("{} — a RustGIS project package.\nOpen it with RustGIS (Project › Open), or unzip it for {}.rgis.\n", name, name); // The package as unzipped, the README with it, within what a zip and a project may hold. @@ -924,6 +926,7 @@ fn package_map(s: &mut Session, mobile: bool, tol: f64, linked: &mut rustgis_dat crate::project::ensure_map_imports_complete(&m)?; // After mobile_map: a hidden layer it drops isn't in the package. linked.extend(left_linked("Package Map", [&m])); + crate::project::mark_internet_only(&mut m); let name = m.name.clone(); // With the map file's header, so an older reader refuses what it can't draw. let (bytes, report) = crate::durable::output_owned(m, crate::project::map_file_bytes)?; diff --git a/crates/engine/src/cmd/workspace.rs b/crates/engine/src/cmd/workspace.rs index 14cb15e4c4..62eb570581 100644 --- a/crates/engine/src/cmd/workspace.rs +++ b/crates/engine/src/cmd/workspace.rs @@ -386,6 +386,9 @@ pub fn commands() -> Vec { s.project.active_map = i; } else { let mut m = a.data.clone(); + // Its layers that documents read from the internet named are held there again + // before anything of the map is read. + crate::project::apply_internet_only(&m); let map_name = offline_map_name(&a.name); let taken = |n: &str| s.project.maps.iter().any(|m| m.name.eq_ignore_ascii_case(n)); m.name = if taken(&map_name) { super::numbered(&map_name, taken) } else { map_name.clone() }; diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 04e9e42bc0..b1c6d701e4 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -69,6 +69,9 @@ pub const FORMAT: u32 = 2; /// so what a later RustGIS adds to format 2, and an older one would lose, is listed there and /// refused by name instead. pub const READ_FORMAT: u32 = 2; +/// Layers held to the internet (`internetOnly` on a tile layer, `internet_only` on a map layer): an +/// older reader would save the project again without the hold, so it refuses the project by name. +pub const INTERNET_ONLY: &str = "internet-only"; /// The saved additions this RustGIS understands. Writers require only capabilities used by /// their payload, so a format-2 reader without them refuses instead of discarding their fields. pub const CAPABILITIES: &[&str] = &[ @@ -112,6 +115,7 @@ pub const CAPABILITIES: &[&str] = &[ "label-guide", PROJECT_CRS, "dggs-system", + INTERNET_ONLY, ]; /// An offline area keeping the versions that lost a sync or a Bring Back /// (`OfflineArea::conflicts`, #2468): an older reader would save it again without them. @@ -1711,9 +1715,6 @@ impl Project { false } }); - // Layers whose addresses a document read from the internet named are held there again, - // before anything below is read (a raster in place, a streamed source). - apply_internet_only(m); // GeoTIFFs read in place are raster layers (a project from before saved tile layers), // so they don't count toward the tile layers kept. As the project opens only: a tile // layer added this session stays one until the project is opened again. @@ -1738,6 +1739,10 @@ impl Project { } done.tiles_over_limit.add(m.tiles.len().saturating_sub(rustgis_map::tiles::MAX_TILE_LAYERS), &m.name); m.tiles.truncate(rustgis_map::tiles::MAX_TILE_LAYERS); + // Layers whose addresses a document read from the internet named are held there again, + // before anything below is read (a raster in place, a streamed source); only the tile + // layers kept. + apply_internet_only(m); #[cfg(not(target_arch = "wasm32"))] for t in &mut m.tiles { if t.error.is_none() @@ -2957,7 +2962,10 @@ impl Durable for ModelGraph { /// Marks, before a map is written, each layer whose addresses this session recorded as named by a /// document read from the internet ([`cache::recorded_public`]), so the restriction is saved with /// it (`internetOnly`) and [`apply_internet_only`] puts it back when the map is read again. Only -/// ever sets the mark: a layer marked once stays held to the internet. +/// ever sets the mark: a layer marked once stays held to the internet. A layer is held or not as a +/// whole, since its addresses come from one document (a tile layer's template, legends and dated +/// steps from its capabilities or tile set; a map layer's sources from the one add): a tile layer +/// is marked by its template's record, a map layer by any of its sources'. /// /// [`cache::recorded_public`]: crate::render::rustgis_tiles::cache::recorded_public pub(crate) fn mark_internet_only(map: &mut Map) { @@ -3007,9 +3015,6 @@ pub(crate) fn apply_internet_only(map: &Map) { /// [`apply_internet_only`] for one layer. fn apply_layer_internet_only(layer: &rustgis_map::Layer) { use crate::render::rustgis_tiles::cache; - if !layer.internet_only { - return; - } for address in layer_web_addresses(layer) { cache::restrict_to_public(address); for (_, part) in rustgis_data::io::shapefile_part_urls(address).unwrap_or_default() { @@ -3054,8 +3059,9 @@ mod internet_only_tests { use crate::{Project, Session}; use serde_json::json; - /// The session's record of what each address may reach, as a new process has it: nothing - /// recorded. ([`cache::clear_public_restrictions`] would clear other tests' records too.) + /// The session's record of these addresses as a new process has it, as far as their reach goes + /// (`Local`: they are recorded as named by the user, which a hold replaces). + /// ([`cache::clear_public_restrictions`] would clear other tests' records too.) fn forget(addresses: &[&str]) { for a in addresses { cache::allow_named(a); @@ -3099,6 +3105,18 @@ mod internet_only_tests { assert_eq!(cache::ceiling_for(a), Reach::Public, "{a}, as added"); } let (saved, _) = s.project.saved_text(None).unwrap(); + // Required by name: an older RustGIS refuses the project rather than saving it again + // without the hold; a map file and a layer file the same. + let requires = |v: &serde_json::Value| v["requires"].as_array().is_some_and(|r| r.iter().any(|c| c == super::INTERNET_ONLY)); + assert!(requires(&serde_json::from_str(&saved).unwrap()), "{saved}"); + let file = |bytes: Vec| serde_json::from_slice::(&bytes).unwrap(); + assert!(requires(&file(super::map_file_bytes(s.map()).unwrap()))); + let marked = s.map().layer(id).unwrap(); + assert!(requires(&file(super::layer_file_bytes(marked).unwrap()))); + // Saved with nothing held, nothing is required. + let mut plain = Session::new(Project::default()); + plain.run("layer.addDataText", &json!({"fileName": "plain.geojson", "text": roads})).unwrap(); + assert!(!requires(&serde_json::from_str(&plain.project.saved_text(None).unwrap().0).unwrap())); let ceilings = |text: &str| { forget(&addresses); let s = Session::new(Project::from_json(text).unwrap()); @@ -3127,6 +3145,82 @@ mod internet_only_tests { drop(s); } + /// An offline area's snapshot keeps the hold: marked when the project is written and held + /// again when the area is opened as a map. A project package and a map package carry the mark + /// too. + #[test] + fn offline_maps_and_packages_keep_the_hold() { + let template = "https://saved-reach-offline.example/tiles/{z}/{x}/{y}.png"; + let mut s = Session::new(Project::default()); + s.run("map.addTiles", &json!({"url": template, "name": "Held", "overlay": true})).unwrap(); + cache::restrict_to_public(template); + let data = s.map().clone(); + s.project.offline_areas.push(super::OfflineArea { + id: String::new(), + name: "Field".into(), + map: "Map".into(), + extent: rustgis_geom::Extent::new(0.0, 0.0, 1.0, 1.0), + created: 0.0, + synced: 0.0, + generation: String::new(), + returned: Vec::new(), + ids: Default::default(), + conflicts: Default::default(), + data, + }); + s.map_mut().tiles.clear(); + // Packages: the project's (its offline area's snapshot) and the map's (a held layer on it). + let mut packaged = Session::new(Project::from_json(&s.project.saved_text(None).unwrap().0).unwrap()); + packaged.run("map.addTiles", &json!({"url": template, "name": "Held", "overlay": true})).unwrap(); + cache::restrict_to_public(template); + for kind in ["projectPackage", "mapPackage"] { + let (_, bytes, _) = crate::cmd::items::item_output(&mut packaged, kind, &json!({})).unwrap(); + let entries = rustgis_data::zip::read(&bytes).unwrap(); + // The map's own tiles (a project's first map, or a map file's), not the snapshot's. + let marked = entries.iter().filter(|(name, _)| name.ends_with(".rgis") || name.ends_with(".rgismap")).any(|(_, text)| { + let v: serde_json::Value = serde_json::from_slice(text).unwrap_or_default(); + let tiles = v.get("maps").and_then(|m| m.get(0)).unwrap_or(&v)["tiles"].as_array().cloned().unwrap_or_default(); + tiles.iter().any(|t| t["name"] == "Held" && t["internetOnly"] == true) + }); + assert!(marked, "{kind}: {:?}", entries.iter().map(|(n, _)| n).collect::>()); + } + let (saved, _) = s.project.saved_text(None).unwrap(); + assert!(s.project.offline_areas[0].data.tiles[0].internet_only, "the snapshot is marked"); + forget(&[template]); + let mut reopened = Session::new(Project::from_json(&saved).unwrap()); + assert_eq!(cache::ceiling_for(template), Reach::Local, "a snapshot isn't read until its area is opened"); + reopened.run("offline.open", &json!({"name": "Field"})).unwrap(); + assert_eq!(cache::ceiling_for(template), Reach::Public, "opened as a map, it is held again"); + } + + /// Only the tile layers a project keeps are held: those past the limit, left out (and said), + /// record nothing. + #[test] + fn tile_layers_past_the_limit_record_nothing() { + let template = |i: usize| format!("https://saved-reach-limit-{i}.example/tiles/{{z}}/{{x}}/{{y}}.png"); + let mut s = Session::new(Project::default()); + let first = template(0); + s.run("map.addTiles", &json!({"url": first, "name": "Held", "overlay": true})).unwrap(); + cache::restrict_to_public(&first); + let (saved, _) = s.project.saved_text(None).unwrap(); + let mut v: serde_json::Value = serde_json::from_str(&saved).unwrap(); + let tile = v["maps"][0]["tiles"][0].clone(); + let mut tiles = Vec::new(); + for i in 0..=rustgis_map::tiles::MAX_TILE_LAYERS { + let mut t = tile.clone(); + t["url"] = json!(template(i)); + t["name"] = json!(format!("Held {i}")); + tiles.push(t); + } + v["maps"][0]["tiles"] = json!(tiles); + let last = template(rustgis_map::tiles::MAX_TILE_LAYERS); + forget(&[first.as_str(), last.as_str()]); + let reopened = Session::new(Project::from_json(&v.to_string()).unwrap()); + assert_eq!(reopened.map().tiles.len(), rustgis_map::tiles::MAX_TILE_LAYERS); + assert_eq!(cache::ceiling_for(&first), Reach::Public, "a kept layer is held"); + assert_eq!(cache::ceiling_for(&last), Reach::Local, "the one left out records nothing"); + } + /// The fixture project's marked WMS layer opens with its template and legend held to the /// internet; without the mark, they are the user's own. #[test] diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 1eb0c45e87..2a485b83d2 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -528,6 +528,7 @@ fn layer_capabilities(layer: &Layer) -> Vec<&'static str> { (layer.has_picture_markers(), "picture-markers"), (zarr_window(layer), "zarr-window"), (label_guide(layer), "label-guide"), + (layer.internet_only, super::INTERNET_ONLY), (held_natively(&layer.dataset), super::NATIVE_COORDINATES), ] .into_iter() @@ -555,6 +556,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static ) = (false, false, false, false, false, false, false, false, false, false, false, false, false, false, false); let mut polygon = false; let (mut offline_area_id, mut paper, mut native, mut guided) = (false, false, false, false); + let mut internet_only = false; for map in maps { offline_area_id |= map.offline_area_id.is_some(); // A blank basemap's paper colour (#2532), which an older reader would draw and save white. @@ -580,6 +582,9 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static // The layer a block's walls are coloured by (#2173), which an older reader would save away. walls_layer |= t.block.as_ref().is_some_and(|b| b.walls_layer.is_some()); } + // A layer held to the internet (its addresses came from a document read from there), which + // an older reader would save again without the hold. + internet_only |= map.tiles.iter().any(|t| t.internet_only) || map.layers.iter().any(|l| l.internet_only); relief |= map.layers.iter().any(relief_effects); light |= map.layers.iter().any(relief_light); sized |= map.layers.iter().any(|layer| layer.size_by.is_some()); @@ -611,6 +616,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static (mgrs, "graticule-mgrs"), (on_top, "graticule-on-top"), (grid_color, "graticule-color"), + (internet_only, super::INTERNET_ONLY), ] .into_iter() .filter_map(|(used, name)| used.then_some(name)) diff --git a/docs/maintaining.md b/docs/maintaining.md index 04af512492..4cb970b2f0 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -157,6 +157,11 @@ Projects, map files and layer files with a window of a Zarr variable that follow reader refuses them instead of reading the whole map at each step. A saved `layer.addZarr` command with both needs nothing: an older RustGIS refuses it when it runs. +Projects, map files and layer files with a layer held to the internet (one whose addresses a +document read from the internet named: `internetOnly` on a tile layer, `internet_only` on a map +layer) require `internet-only`, so an older reader refuses them instead of reading the layer's +addresses wherever their names resolve and saving the project again without the hold. + Projects, map files and layer files with a label class curved along a guide line layer (`labels.placement` with a `guide`) require `label-guide`, so an older reader refuses them instead of placing those labels as without it and saving them again without the guide. A saved diff --git a/schema/fixtures/internet_only.rgis b/schema/fixtures/internet_only.rgis index 5457be9922..39efd53f68 100644 --- a/schema/fixtures/internet_only.rgis +++ b/schema/fixtures/internet_only.rgis @@ -1,5 +1,8 @@ { "format": 2, + "requires": [ + "internet-only" + ], "name": "Internet only", "maps": [ { diff --git a/schema/project.schema.json b/schema/project.schema.json index 7cbc133e20..cb32372d6c 100644 --- a/schema/project.schema.json +++ b/schema/project.schema.json @@ -1275,7 +1275,8 @@ "layout-text-size", "label-guide", "project-crs", - "dggs-system" + "dggs-system", + "internet-only" ], "type": "string" }, @@ -1379,7 +1380,8 @@ "layout-text-size", "label-guide", "project-crs", - "dggs-system" + "dggs-system", + "internet-only" ], "x-rustgis-reads-format": 2, "x-rustgis-writes-format": 2 From f51c1082d400e450dc4fb1e5a95902ec656a95a7 Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 11:56:52 -0600 Subject: [PATCH 3/7] fix(project): hold marked layers only as they are read from a file The hold is applied as a project, map file, layer file or offline area is read, not on every later repair, so an address the user names afterwards stays theirs. A marked COG tile layer read in place as a raster layer keeps its mark. --- crates/engine/src/cmd/layer.rs | 5 ++++ crates/engine/src/cmd/tiles.rs | 2 ++ crates/engine/src/project.rs | 46 +++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index e22a5d774d..45e021d68c 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -4568,6 +4568,11 @@ pub(crate) fn add_layer_text(s: &mut Session, text: &str) -> CmdResult { // A binding in a file is no authority to use a login here. crate::s3_connections::clear_bindings(layer.addresses_mut()); crate::project::clear_login_bindings(layer.addresses_mut()); + // A layer whose addresses a document read from the internet named is held there again before + // it is read (the repair below reads it). + if layer.internet_only { + crate::project::apply_layer_internet_only(&layer); + } // A fresh id and a unique name in this map; the rest goes through project repair. let base = layer.name.clone(); let mut i = 1; diff --git a/crates/engine/src/cmd/tiles.rs b/crates/engine/src/cmd/tiles.rs index 1689e8ad16..c95c425d56 100644 --- a/crates/engine/src/cmd/tiles.rs +++ b/crates/engine/src/cmd/tiles.rs @@ -760,6 +760,8 @@ pub(crate) fn cog_tiles_to_rasters(m: &mut rustgis_map::Map) { // anonymous plugin command added takes no saved login, as before. l.connection = t.connection.clone(); l.anonymous = t.anonymous; + // Held to the internet, as the tile layer was. + l.internet_only = t.internet_only; } // Just over the layer it was drawn over, in its group; under them all without one. let group = t.over.and_then(|o| m.group_of(o).map(|g| g.id)); diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index b1c6d701e4..08d990cfe3 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1741,8 +1741,11 @@ impl Project { m.tiles.truncate(rustgis_map::tiles::MAX_TILE_LAYERS); // Layers whose addresses a document read from the internet named are held there again, // before anything below is read (a raster in place, a streamed source); only the tile - // layers kept. - apply_internet_only(m); + // layers kept, and only as they are read from a file: a later repair (another layer + // added) leaves an address the user has named since as theirs. + if opened { + apply_internet_only(m); + } #[cfg(not(target_arch = "wasm32"))] for t in &mut m.tiles { if t.error.is_none() @@ -3012,8 +3015,8 @@ pub(crate) fn apply_internet_only(map: &Map) { } } -/// [`apply_internet_only`] for one layer. -fn apply_layer_internet_only(layer: &rustgis_map::Layer) { +/// [`apply_internet_only`] for one marked layer (a layer file's, before it is added). +pub(crate) fn apply_layer_internet_only(layer: &rustgis_map::Layer) { use crate::render::rustgis_tiles::cache; for address in layer_web_addresses(layer) { cache::restrict_to_public(address); @@ -3125,6 +3128,20 @@ mod internet_only_tests { (addresses.map(cache::ceiling_for), marked) }; assert_eq!(ceilings(&saved), ([Reach::Public; 4], 3), "opened again in a new session"); + // A map file and a layer file of the held layers hold them too. + forget(&addresses); + let mut imported = Session::new(Project::default()); + imported.run("map.import", &json!({"text": saved})).unwrap(); + assert_eq!(cache::ceiling_for(&template), Reach::Public, "map.import"); + forget(&addresses); + let layer_file = String::from_utf8(super::layer_file_bytes(s.map().layer(id).unwrap()).unwrap()).unwrap(); + imported.run("layer.addLayerFile", &json!({"text": layer_file})).unwrap(); + assert_eq!(cache::ceiling_for(&features), Reach::Public, "layer.addLayerFile"); + // Held as the file is read, not again later: an address the user names afterwards stays + // theirs when another layer is added (a layer file, which repairs the project again). + cache::allow_named(&template); + imported.run("layer.addLayerFile", &json!({"text": layer_file})).unwrap(); + assert_eq!(cache::ceiling_for(&template), Reach::Local, "named by the user since"); // An older RustGIS's project, without the mark: as before, the user's own. let mut older: serde_json::Value = serde_json::from_str(&saved).unwrap(); let mut dropped = 0; @@ -3193,6 +3210,27 @@ mod internet_only_tests { assert_eq!(cache::ceiling_for(template), Reach::Public, "opened as a map, it is held again"); } + /// A marked cloud-optimised GeoTIFF tile layer, read in place as a raster layer when its + /// project opens, keeps the mark and is held. + #[test] + fn a_marked_cog_tile_stays_held_as_a_raster_layer() { + let tif = "https://saved-reach-cog.example/scene.tif"; + let mut s = Session::new(Project::default()); + s.run("map.addTiles", &json!({"url": "https://saved-reach-cog.example/{z}/{x}/{y}.png", "name": "Scene", "overlay": true})) + .unwrap(); + cache::restrict_to_public("https://saved-reach-cog.example/{z}/{x}/{y}.png"); + let (saved, _) = s.project.saved_text(None).unwrap(); + let mut v: serde_json::Value = serde_json::from_str(&saved).unwrap(); + v["maps"][0]["tiles"][0]["kind"] = json!("cog"); + v["maps"][0]["tiles"][0]["url"] = json!(tif); + assert_eq!(v["maps"][0]["tiles"][0]["internetOnly"], true); + forget(&[tif]); + let reopened = Session::new(Project::from_json(&v.to_string()).unwrap()); + let layer = reopened.map().layers.iter().find(|l| l.raster.is_some()).expect("read in place as a raster layer"); + assert!(layer.internet_only); + assert_eq!(cache::ceiling_for(tif), Reach::Public); + } + /// Only the tile layers a project keeps are held: those past the limit, left out (and said), /// record nothing. #[test] From 43f07d6e37ab2d37c13bfb41a83ac4e7c7cd45d8 Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 14:00:07 -0600 Subject: [PATCH 4/7] fix(project): mark follows the record when saved; say when opening fills the record An address the user names after a document named it is saved unmarked, so it reads as theirs when the project is opened again; offline snapshots, which aren't read until opened, keep their mark. Opening a project, an offline map or a layer file that fills the record of held addresses now says so. --- crates/engine/src/cmd/items.rs | 4 +- crates/engine/src/cmd/layer.rs | 4 ++ crates/engine/src/cmd/workspace.rs | 6 +++ crates/engine/src/project.rs | 68 +++++++++++++++++++++---- crates/engine/tests/held_record_full.rs | 41 +++++++++++++++ crates/tiles/src/cache.rs | 7 +++ 6 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 crates/engine/tests/held_record_full.rs diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index b51616455a..6a5c0fb877 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -926,7 +926,7 @@ fn package_map(s: &mut Session, mobile: bool, tol: f64, linked: &mut rustgis_dat crate::project::ensure_map_imports_complete(&m)?; // After mobile_map: a hidden layer it drops isn't in the package. linked.extend(left_linked("Package Map", [&m])); - crate::project::mark_internet_only(&mut m); + crate::project::mark_internet_only(&mut m, false); let name = m.name.clone(); // With the map file's header, so an older reader refuses what it can't draw. let (bytes, report) = crate::durable::output_owned(m, crate::project::map_file_bytes)?; @@ -1834,7 +1834,7 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve crate::project::ensure_map_imports_complete(map)?; let mut map = embedded_map(map, &mut MAX_EMBED.clone()); // What documents read from the internet named stays held there when the file is read. - crate::project::mark_internet_only(&mut map); + crate::project::mark_internet_only(&mut map, false); let name = map.name.clone(); (name, durable_bytes_with(s, map, crate::project::map_file_bytes)?) } diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 45e021d68c..d1f7fbf2e8 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -4571,7 +4571,11 @@ pub(crate) fn add_layer_text(s: &mut Session, text: &str) -> CmdResult { // A layer whose addresses a document read from the internet named is held there again before // it is read (the repair below reads it). if layer.internet_only { + let full = crate::render::rustgis_tiles::cache::public_restrictions_full(); crate::project::apply_layer_internet_only(&layer); + if !full && crate::render::rustgis_tiles::cache::public_restrictions_full() { + s.notify(crate::project::held_full_notice(&format!("the layer '{}'", layer.name)), false); + } } // A fresh id and a unique name in this map; the rest goes through project repair. let base = layer.name.clone(); diff --git a/crates/engine/src/cmd/workspace.rs b/crates/engine/src/cmd/workspace.rs index 62eb570581..06cc6297fc 100644 --- a/crates/engine/src/cmd/workspace.rs +++ b/crates/engine/src/cmd/workspace.rs @@ -388,7 +388,10 @@ pub fn commands() -> Vec { let mut m = a.data.clone(); // Its layers that documents read from the internet named are held there again // before anything of the map is read. + let full = crate::render::rustgis_tiles::cache::public_restrictions_full(); crate::project::apply_internet_only(&m); + let filled = !full && crate::render::rustgis_tiles::cache::public_restrictions_full(); + let area_name = a.name.clone(); let map_name = offline_map_name(&a.name); let taken = |n: &str| s.project.maps.iter().any(|m| m.name.eq_ignore_ascii_case(n)); m.name = if taken(&map_name) { super::numbered(&map_name, taken) } else { map_name.clone() }; @@ -410,6 +413,9 @@ pub fn commands() -> Vec { } s.project.maps.push(m); s.project.active_map = s.project.maps.len() - 1; + if filled { + s.notify(crate::project::held_full_notice(&format!("the offline map '{area_name}'")), false); + } } s.active_layer = s.map().layers.first().map(|l| l.id); s.zoom_to(&extent); diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 08d990cfe3..653428fff8 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1744,7 +1744,11 @@ impl Project { // layers kept, and only as they are read from a file: a later repair (another layer // added) leaves an address the user has named since as theirs. if opened { + let full = crate::render::rustgis_tiles::cache::public_restrictions_full(); apply_internet_only(m); + if !full && crate::render::rustgis_tiles::cache::public_restrictions_full() { + done.held_full.add(1, &m.name); + } } #[cfg(not(target_arch = "wasm32"))] for t in &mut m.tiles { @@ -1868,8 +1872,11 @@ impl Project { /// Marks every map's layers held to the internet ([`mark_internet_only`]), before writing. pub(crate) fn mark_internet_only(&mut self) { - for map in self.maps.iter_mut().chain(self.offline_areas.iter_mut().map(|area| &mut area.data)) { - mark_internet_only(map); + for map in &mut self.maps { + mark_internet_only(map, false); + } + for area in &mut self.offline_areas { + mark_internet_only(&mut area.data, true); } } @@ -2521,6 +2528,8 @@ struct Repaired { tile_settings: Tally, tiles_removed: Tally, tiles_over_limit: Tally, + /// Holding a map's layers to the internet filled the record of held addresses. + held_full: Tally, values_cut: Tally, } @@ -2674,6 +2683,8 @@ impl Repaired { vec![("limit", rustgis_map::tiles::MAX_TILE_LAYERS.to_string().into())], ), ); + let t = &self.held_full; + say(ReadPart::Maps, t, message(HELD_FULL, t, vec![])); let t = &self.values_cut; say( ReadPart::Maps, @@ -2961,32 +2972,50 @@ impl Durable for ModelGraph { } } -/// Enforces the opening bound inside the formatter, before any destination is replaced. +/// What is said when holding `place`'s layers to the internet fills the record of held addresses, +/// outside a file's read (an offline area opened, a layer file added). +pub(crate) fn held_full_notice(place: &str) -> String { + format!( + "holding {place} to the internet filled the record of addresses held there: until RustGIS is restarted, every address is held to the internet, and services on this computer or the local network can't be reached" + ) +} + +/// What is said when holding layers to the internet fills the record of held addresses: from then +/// on every address is held there. +pub(crate) const HELD_FULL: &str = "holding the layers whose addresses came from documents read from the internet filled the record of such addresses {when} (in {places}): until RustGIS is restarted, every address is held to the internet, and services on this computer or the local network can't be reached"; + /// Marks, before a map is written, each layer whose addresses this session recorded as named by a /// document read from the internet ([`cache::recorded_public`]), so the restriction is saved with -/// it (`internetOnly`) and [`apply_internet_only`] puts it back when the map is read again. Only -/// ever sets the mark: a layer marked once stays held to the internet. A layer is held or not as a +/// it (`internetOnly`) and [`apply_internet_only`] puts it back when the map is read again. The +/// mark follows the record: a layer the user has since pointed elsewhere, or named themselves, +/// loses it (a map read from a file has its held layers recorded again as it is read, so they +/// keep it). An offline area's snapshot (`sticky`), which isn't read until it is opened, keeps the +/// mark it has. A layer is held or not as a /// whole, since its addresses come from one document (a tile layer's template, legends and dated /// steps from its capabilities or tile set; a map layer's sources from the one add): a tile layer /// is marked by its template's record, a map layer by any of its sources'. /// /// [`cache::recorded_public`]: crate::render::rustgis_tiles::cache::recorded_public -pub(crate) fn mark_internet_only(map: &mut Map) { +pub(crate) fn mark_internet_only(map: &mut Map, sticky: bool) { use crate::render::rustgis_tiles::cache; for tile in &mut map.tiles { - tile.internet_only |= cache::recorded_public(&tile.url); + tile.internet_only = (sticky && tile.internet_only) || cache::recorded_public(&tile.url); } for layer in &mut map.layers { - mark_layer_internet_only(layer); + layer.internet_only = (sticky && layer.internet_only) || layer_recorded(layer); } } /// [`mark_internet_only`] for one layer: marked when an address its source is read again from was /// recorded as named by a document read from the internet. pub(crate) fn mark_layer_internet_only(layer: &mut rustgis_map::Layer) { - use crate::render::rustgis_tiles::cache; - let recorded = layer_web_addresses(layer).any(cache::recorded_public); - layer.internet_only |= recorded; + layer.internet_only = layer_recorded(layer); +} + +/// Whether any address a layer's source is read again from is recorded as named by a document read +/// from the internet. +fn layer_recorded(layer: &rustgis_map::Layer) -> bool { + layer_web_addresses(layer).any(crate::render::rustgis_tiles::cache::recorded_public) } /// The web addresses a layer's source is read again from (local paths left out). @@ -3026,6 +3055,7 @@ pub(crate) fn apply_layer_internet_only(layer: &rustgis_map::Layer) { } } +/// Enforces the opening bound inside the formatter, before any destination is replaced. fn project_text(p: &Project) -> Result { let max = max_bytes(); json_within(p, max)?.ok_or_else(|| format!("the project is too large to save (maximum {})", limit_said(max))) @@ -3155,6 +3185,22 @@ mod internet_only_tests { } assert_eq!(dropped, 3); assert_eq!(ceilings(&older.to_string()), ([Reach::Local; 4], 0), "a project without the mark"); + // The mark follows the record: an address the user names afterwards (which clears its + // record) is saved unmarked, and reads as theirs. + for a in addresses { + cache::restrict_to_public(a); + } + cache::allow_named(&template); + let (again, _) = s.project.saved_text(None).unwrap(); + let v: serde_json::Value = serde_json::from_str(&again).unwrap(); + let marked = |name: &str| v["maps"][0]["tiles"].as_array().unwrap().iter().any(|t| t["name"] == name && t["internetOnly"] == true); + assert!(!marked("Roads"), "named by the user since"); + assert!(marked("Roads style"), "the rest stay marked"); + forget(&addresses); + let reopened = Session::new(Project::from_json(&again).unwrap()); + assert_eq!(cache::ceiling_for(&template), Reach::Local); + assert_eq!(cache::ceiling_for(&style), Reach::Public); + drop(reopened); // The mark only narrows: an address held to the internet stays held in a project without it. cache::restrict_to_public(&template); let s = Session::new(Project::from_json(&older.to_string()).unwrap()); diff --git a/crates/engine/tests/held_record_full.rs b/crates/engine/tests/held_record_full.rs new file mode 100644 index 0000000000..3100d5d7bd --- /dev/null +++ b/crates/engine/tests/held_record_full.rs @@ -0,0 +1,41 @@ +//! Opening a project that fills the record of addresses held to the internet says so: from then +//! on every address is held there, for the rest of the session. +//! +//! Its own test binary: it fills the process-wide record, which would hold every other test's +//! addresses to the internet too. + +use rustgis_engine::map as rustgis_map; +use rustgis_engine::render::rustgis_tiles::{address::Reach, cache}; +use rustgis_engine::{Project, Session}; +use serde_json::json; + +/// A project with one tile layer held to the internet, with `dates` dated files. +fn held(dates: usize) -> String { + let mut s = Session::new(Project::default()); + let template = format!("https://held-full-{dates}.example/scene.tif"); + s.run("map.addTiles", &json!({"url": "https://held-full.example/{z}/{x}/{y}.png", "name": "Scene", "overlay": true})).unwrap(); + let mut v: serde_json::Value = serde_json::to_value(&s.project).unwrap(); + let tile = &mut v["maps"][0]["tiles"][0]; + tile["url"] = json!(template); + tile["internetOnly"] = json!(true); + tile["timeUrls"] = + json!((0..dates).map(|i| json!([i as f64, format!("https://held-full-{dates}.example/{i}.tif")])).collect::>()); + v["requires"] = json!(["internet-only"]); + v.to_string() +} + +#[test] +fn a_project_that_fills_the_record_of_held_addresses_says_so() { + let said = |s: &Session| s.notices_since(0).iter().filter(|n| n.text.contains("filled the record")).count(); + // Within the record: nothing said, and the user's own addresses are theirs. + let opened = Session::new(Project::from_json(&held(10)).unwrap()); + assert_eq!(said(&opened), 0); + assert!(!cache::public_restrictions_full()); + assert_eq!(cache::ceiling_for("http://192.168.1.5/tiles/0/0/0.png"), Reach::Local); + // Past it (a data cube with more dated files than the record holds): said once, and from then + // on every address is held to the internet. + let opened = Session::new(Project::from_json(&held(rustgis_map::tiles::MAX_TIME_URLS)).unwrap()); + assert_eq!(said(&opened), 1, "{:?}", opened.notices_since(0).iter().map(|n| &n.text).collect::>()); + assert!(cache::public_restrictions_full()); + assert_eq!(cache::ceiling_for("http://192.168.1.5/tiles/0/0/0.png"), Reach::Public); +} diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index 38038e9c28..d83aa95cb9 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -617,6 +617,13 @@ pub fn recorded_public(url: &str) -> bool { p.exact.contains(base) || (!p.named_local.contains(base) && p.templates.iter().any(|tpl| tpl.matches(base))) } +/// Whether the record of addresses held to the internet is full, so every address not named by the +/// user is held there ([`ceiling_for`]) until the process ends: for the caller that filled it to +/// say. +pub fn public_restrictions_full() -> bool { + public_only().lock().unwrap_or_else(|e| e.into_inner()).saturated +} + /// Resets document-origin public restrictions recorded by [`restrict_to_public`] and [`allow_named`]. pub fn clear_public_restrictions() { let mut p = public_only().lock().unwrap_or_else(|e| e.into_inner()); From b13e693a58090323e1a618252558aa6c3fb4bd12 Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 14:27:29 -0600 Subject: [PATCH 5/7] fix(project): mark a tile layer while any of its addresses is recorded A legend a document named stays held after the user names the layer's template, as a map layer is already marked by any of its sources. --- crates/engine/src/project.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 653428fff8..cd77048edb 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -2990,16 +2990,17 @@ pub(crate) const HELD_FULL: &str = "holding the layers whose addresses came from /// mark follows the record: a layer the user has since pointed elsewhere, or named themselves, /// loses it (a map read from a file has its held layers recorded again as it is read, so they /// keep it). An offline area's snapshot (`sticky`), which isn't read until it is opened, keeps the -/// mark it has. A layer is held or not as a -/// whole, since its addresses come from one document (a tile layer's template, legends and dated -/// steps from its capabilities or tile set; a map layer's sources from the one add): a tile layer -/// is marked by its template's record, a map layer by any of its sources'. +/// mark it has. A layer is held or not as a whole, since its addresses come from one document (a +/// tile layer's template, legends and dated steps from its capabilities or tile set; a map layer's +/// sources from the one add): it is marked while any of them is recorded, so a legend a document +/// named stays held though the user has named the template since, and the rest narrow with it. /// /// [`cache::recorded_public`]: crate::render::rustgis_tiles::cache::recorded_public pub(crate) fn mark_internet_only(map: &mut Map, sticky: bool) { use crate::render::rustgis_tiles::cache; for tile in &mut map.tiles { - tile.internet_only = (sticky && tile.internet_only) || cache::recorded_public(&tile.url); + tile.internet_only = + (sticky && tile.internet_only) || cache::recorded_public(&tile.url) || tile.addresses().any(cache::recorded_public); } for layer in &mut map.layers { layer.internet_only = (sticky && layer.internet_only) || layer_recorded(layer); @@ -3190,12 +3191,25 @@ mod internet_only_tests { for a in addresses { cache::restrict_to_public(a); } + let marked = |text: &str, name: &str| { + let v: serde_json::Value = serde_json::from_str(text).unwrap(); + v["maps"][0]["tiles"].as_array().unwrap().iter().any(|t| t["name"] == name && t["internetOnly"] == true) + }; + // The template named, its legend still came from the document: held whole. + cache::allow_named(&template); + let (named_template, _) = s.project.saved_text(None).unwrap(); + assert!(marked(&named_template, "Roads"), "its legend is still the document's"); + forget(&addresses); + let reopened = Session::new(Project::from_json(&named_template).unwrap()); + assert_eq!(cache::ceiling_for(&legend), Reach::Public); + drop(reopened); + // Every address of it named: saved unmarked. + cache::restrict_to_public(&style); cache::allow_named(&template); + cache::allow_named(&legend); let (again, _) = s.project.saved_text(None).unwrap(); - let v: serde_json::Value = serde_json::from_str(&again).unwrap(); - let marked = |name: &str| v["maps"][0]["tiles"].as_array().unwrap().iter().any(|t| t["name"] == name && t["internetOnly"] == true); - assert!(!marked("Roads"), "named by the user since"); - assert!(marked("Roads style"), "the rest stay marked"); + assert!(!marked(&again, "Roads"), "named by the user since"); + assert!(marked(&again, "Roads style"), "the rest stay marked"); forget(&addresses); let reopened = Session::new(Project::from_json(&again).unwrap()); assert_eq!(cache::ceiling_for(&template), Reach::Local); From cb1fa0196215926198c73f087c9152f005d80f04 Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 15:53:28 -0600 Subject: [PATCH 6/7] fix(project): keep marks the full record can't hold; say what is written unmarked; mark templates A layer read marked keeps its mark though the record has no room for its addresses, until the user names one of them. A layer held only because the record is full is written unmarked, and that is said. Templates carry the mark, as packages and map files do. --- crates/engine/src/cmd/items.rs | 24 ++++++-- crates/engine/src/durable.rs | 5 ++ crates/engine/src/project.rs | 77 +++++++++++++++++-------- crates/engine/tests/held_record_full.rs | 30 +++++++--- crates/tiles/src/cache.rs | 6 ++ 5 files changed, 105 insertions(+), 37 deletions(-) diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index 6a5c0fb877..63f0ddb6cb 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -847,7 +847,8 @@ fn package_project(s: &mut Session, notes: &mut rustgis_data::loss::Notes) -> Re // Offline areas are maps too, and their copies keep a streamed layer's source and the tiles. let linked = left_linked("Package Project", p.maps.iter().chain(p.offline_areas.iter().map(|a| &a.data))); // What documents read from the internet named stays held there when the package is read. - p.mark_internet_only(); + let held = p.mark_internet_only(); + say_held_unmarked(s, held); let name = p.name.clone(); let readme = format!("{} — a RustGIS project package.\nOpen it with RustGIS (Project › Open), or unzip it for {}.rgis.\n", name, name); // The package as unzipped, the README with it, within what a zip and a project may hold. @@ -926,10 +927,11 @@ fn package_map(s: &mut Session, mobile: bool, tol: f64, linked: &mut rustgis_dat crate::project::ensure_map_imports_complete(&m)?; // After mobile_map: a hidden layer it drops isn't in the package. linked.extend(left_linked("Package Map", [&m])); - crate::project::mark_internet_only(&mut m, false); + let held = crate::project::mark_internet_only(&mut m); let name = m.name.clone(); // With the map file's header, so an older reader refuses what it can't draw. - let (bytes, report) = crate::durable::output_owned(m, crate::project::map_file_bytes)?; + let (bytes, mut report) = crate::durable::output_owned(m, crate::project::map_file_bytes)?; + report.held_unmarked = u32::try_from(held).unwrap_or(u32::MAX); crate::durable::notify(s, &report); let kind = if mobile { "mobile map package" } else { "map package" }; let readme = format!("{} — a RustGIS {kind}.\nAdd it to a project with Data › Import.\n", name); @@ -1834,7 +1836,8 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve crate::project::ensure_map_imports_complete(map)?; let mut map = embedded_map(map, &mut MAX_EMBED.clone()); // What documents read from the internet named stays held there when the file is read. - crate::project::mark_internet_only(&mut map, false); + let held = crate::project::mark_internet_only(&mut map); + say_held_unmarked(s, held); let name = map.name.clone(); (name, durable_bytes_with(s, map, crate::project::map_file_bytes)?) } @@ -1845,7 +1848,8 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve return Err("this layer is still downloading; wait for it to finish before saving".into()); } let mut layer = embed_layer(l, &mut MAX_EMBED.clone()); - crate::project::mark_layer_internet_only(&mut layer); + let held = crate::project::mark_layer_internet_only(&mut layer); + say_held_unmarked(s, usize::from(held)); let name = layer.name.clone(); (name, durable_bytes_with(s, layer, crate::project::layer_file_bytes)?) } @@ -1867,6 +1871,9 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve if let Some(n) = ps(p, "name").map(str::trim).filter(|n| !n.is_empty()) { t.name = super::within("name", "a template's name", n, 200)?; } + // What documents read from the internet named stays held there when it is used. + let held = t.mark_internet_only(); + say_held_unmarked(s, held); let name = t.name.clone(); let bytes = durable_bytes(s, t)?; if source_references > 0 { @@ -1969,6 +1976,13 @@ pub(crate) fn save_item(s: &mut Session, kind: &str, p: &Value) -> CmdResult { } /// Consumes the existing item draft, emitting losses after serialization has completed. +/// Says how many layers held to the internet only by a full record were written without the hold. +fn say_held_unmarked(s: &mut Session, held: usize) { + if held > 0 { + s.notify(format!("{held} {}", crate::project::HELD_UNMARKED), false); + } +} + fn durable_bytes(s: &mut Session, value: T) -> Result, String> { durable_bytes_with(s, value, to_json) } diff --git a/crates/engine/src/durable.rs b/crates/engine/src/durable.rs index d9f4e4d606..9e8255c271 100644 --- a/crates/engine/src/durable.rs +++ b/crates/engine/src/durable.rs @@ -27,6 +27,9 @@ pub struct Report { pub(crate) numbers: u32, /// First affected dataset names; the total count still covers every dataset. pub(crate) number_places: Vec, + /// Layers held to the internet only because the session's record of such addresses is full, + /// written without the hold ([`crate::project::HELD_UNMARKED`]). + pub(crate) held_unmarked: u32, } impl Report { @@ -72,6 +75,7 @@ impl Report { (self.not_retained, "address(es) exceeded the bridge retention limit; their keys will not survive a round trip"), (self.lost, "address(es) lost their keys when a peer sent back its project; add them again in the receiving session"), (self.reconnect, "database source(s) from a peer require an explicit reconnect before reading"), + (self.held_unmarked, crate::project::HELD_UNMARKED), ( self.executable_changes, "credential-bearing executable field(s) changed when a peer sent back its project; supply missing values before replay", @@ -119,6 +123,7 @@ impl Report { self.executable_changes = self.executable_changes.saturating_add(other.executable_changes); self.reconnect = self.reconnect.saturating_add(other.reconnect); self.numbers = self.numbers.saturating_add(other.numbers); + self.held_unmarked = self.held_unmarked.saturating_add(other.held_unmarked); for place in &other.number_places { if self.number_places.len() < 3 && !self.number_places.contains(place) { self.number_places.push(place.clone()); diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index cd77048edb..ac8cd72586 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1870,24 +1870,24 @@ impl Project { } } - /// Marks every map's layers held to the internet ([`mark_internet_only`]), before writing. - pub(crate) fn mark_internet_only(&mut self) { - for map in &mut self.maps { - mark_internet_only(map, false); - } - for area in &mut self.offline_areas { - mark_internet_only(&mut area.data, true); - } + /// Marks every map's layers held to the internet ([`mark_internet_only`]), before writing; + /// returns how many are held only by a full record, and written without the hold. + pub(crate) fn mark_internet_only(&mut self) -> usize { + let maps = self.maps.iter_mut().chain(self.offline_areas.iter_mut().map(|a| &mut a.data)); + maps.map(mark_internet_only).sum() } /// Writes controlled durable fields and relative paths in one guarded transaction. Live /// fields are restored on every return and native unwind; only explicit saves are remembered. + /// The layers' internet-only marks are the session's own and stay as written + /// ([`mark_internet_only`]). pub fn saved_text(&mut self, dir: Option<&Path>) -> Result<(String, crate::durable::Report), String> { self.ensure_imports_complete()?; - self.mark_internet_only(); + let held = self.mark_internet_only(); let unrecorded = self.bound_address_losses(false); let (text, mut report) = crate::durable::output_remembered(self, dir.and_then(Path::to_str), project_text)?; report.addresses = report.addresses.saturating_add(u32::try_from(unrecorded).unwrap_or(u32::MAX)); + report.held_unmarked = u32::try_from(held).unwrap_or(u32::MAX); Ok((text, report)) } @@ -1907,7 +1907,7 @@ impl Project { /// Text too large to open again is refused. Returns the text and its counted output notices. pub fn recovery_text_with_report(mut self) -> Result<(String, crate::durable::Report), String> { self.omit_pending_imports(); - self.mark_internet_only(); + let held = self.mark_internet_only(); let unrecorded = self.bound_address_losses(false); // Refused as a recovery copy, not as a save, and never built past the limit. let (text, mut report) = crate::durable::output_owned(self, |p| { @@ -1915,6 +1915,7 @@ impl Project { json_within(p, max)?.ok_or_else(|| format!("the project is too large to keep a recovery copy (maximum {})", limit_said(max))) })?; report.addresses = report.addresses.saturating_add(u32::try_from(unrecorded).unwrap_or(u32::MAX)); + report.held_unmarked = u32::try_from(held).unwrap_or(u32::MAX); Ok((text, report)) } @@ -2984,33 +2985,54 @@ pub(crate) fn held_full_notice(place: &str) -> String { /// on every address is held there. pub(crate) const HELD_FULL: &str = "holding the layers whose addresses came from documents read from the internet filled the record of such addresses {when} (in {places}): until RustGIS is restarted, every address is held to the internet, and services on this computer or the local network can't be reached"; +/// What is said when layers held to the internet only by a full record are written without the +/// hold, after their count. +pub(crate) const HELD_UNMARKED: &str = "layer(s) held to the internet only because this session's record of such addresses is full were written without the hold: opened again, their addresses are read as your own"; + /// Marks, before a map is written, each layer whose addresses this session recorded as named by a /// document read from the internet ([`cache::recorded_public`]), so the restriction is saved with -/// it (`internetOnly`) and [`apply_internet_only`] puts it back when the map is read again. The -/// mark follows the record: a layer the user has since pointed elsewhere, or named themselves, -/// loses it (a map read from a file has its held layers recorded again as it is read, so they -/// keep it). An offline area's snapshot (`sticky`), which isn't read until it is opened, keeps the -/// mark it has. A layer is held or not as a whole, since its addresses come from one document (a -/// tile layer's template, legends and dated steps from its capabilities or tile set; a map layer's -/// sources from the one add): it is marked while any of them is recorded, so a legend a document -/// named stays held though the user has named the template since, and the rest narrow with it. +/// it (`internetOnly`) and [`apply_internet_only`] puts it back when the map is read again. A layer +/// marked already (read marked from a file, or saved marked before) keeps the mark, though the +/// record had no room for its addresses, until the user names one of them themselves +/// ([`cache::named_by_user`]), which clears it. A layer is held or not as a whole, since its +/// addresses come from one document (a tile layer's template, legends and dated steps from its +/// capabilities or tile set; a map layer's sources from the one add): it is marked while any of +/// them is recorded, so a legend a document named stays held though the user has named the +/// template since, and the rest narrow with it. +/// +/// Returns how many layers are held to the internet now only because the record is full (added +/// after it filled, so nothing recorded them) and are written unmarked, for the caller to say. /// /// [`cache::recorded_public`]: crate::render::rustgis_tiles::cache::recorded_public -pub(crate) fn mark_internet_only(map: &mut Map, sticky: bool) { +/// [`cache::named_by_user`]: crate::render::rustgis_tiles::cache::named_by_user +pub(crate) fn mark_internet_only(map: &mut Map) -> usize { use crate::render::rustgis_tiles::cache; + let web = |a: &&str| rustgis_map::tiles::is_web(a); + let mut held = 0; for tile in &mut map.tiles { tile.internet_only = - (sticky && tile.internet_only) || cache::recorded_public(&tile.url) || tile.addresses().any(cache::recorded_public); + tile.addresses().any(cache::recorded_public) || (tile.internet_only && !tile.addresses().filter(web).any(cache::named_by_user)); + held += usize::from(held_by_full_record(tile.internet_only, tile.addresses().filter(web))); } for layer in &mut map.layers { - layer.internet_only = (sticky && layer.internet_only) || layer_recorded(layer); + held += usize::from(mark_layer_internet_only(layer)); } + held } -/// [`mark_internet_only`] for one layer: marked when an address its source is read again from was -/// recorded as named by a document read from the internet. -pub(crate) fn mark_layer_internet_only(layer: &mut rustgis_map::Layer) { - layer.internet_only = layer_recorded(layer); +/// [`mark_internet_only`] for one layer; true when it is held only by a full record and is written +/// unmarked. +pub(crate) fn mark_layer_internet_only(layer: &mut rustgis_map::Layer) -> bool { + use crate::render::rustgis_tiles::cache; + layer.internet_only = layer_recorded(layer) || (layer.internet_only && !layer_web_addresses(layer).any(cache::named_by_user)); + held_by_full_record(layer.internet_only, layer_web_addresses(layer)) +} + +/// Whether an unmarked layer with these web addresses is held to the internet now only because the +/// session's record of such addresses is full. +fn held_by_full_record<'a>(marked: bool, mut addresses: impl Iterator) -> bool { + use crate::render::rustgis_tiles::{address::Reach, cache}; + !marked && cache::public_restrictions_full() && addresses.any(|a| cache::ceiling_for(a) == Reach::Public) } /// Whether any address a layer's source is read again from is recorded as named by a document read @@ -3261,6 +3283,11 @@ mod internet_only_tests { }); assert!(marked, "{kind}: {:?}", entries.iter().map(|(n, _)| n).collect::>()); } + // A template keeps the mark on its tile layers too. + let (_, bytes, _) = crate::cmd::items::item_output(&mut packaged, "template", &json!({})).unwrap(); + let v: serde_json::Value = serde_json::from_slice(&bytes).unwrap(); + let tiles = v["maps"][0]["tiles"].as_array().cloned().unwrap_or_default(); + assert!(tiles.iter().any(|t| t["name"] == "Held" && t["internetOnly"] == true), "template: {tiles:?}"); let (saved, _) = s.project.saved_text(None).unwrap(); assert!(s.project.offline_areas[0].data.tiles[0].internet_only, "the snapshot is marked"); forget(&[template]); diff --git a/crates/engine/tests/held_record_full.rs b/crates/engine/tests/held_record_full.rs index 3100d5d7bd..136347c639 100644 --- a/crates/engine/tests/held_record_full.rs +++ b/crates/engine/tests/held_record_full.rs @@ -1,8 +1,9 @@ //! Opening a project that fills the record of addresses held to the internet says so: from then -//! on every address is held there, for the rest of the session. +//! on every address is held there, for the rest of the session. With the record full, a layer read +//! marked keeps its mark, and one held only because the record is full is said when written. //! -//! Its own test binary: it fills the process-wide record, which would hold every other test's -//! addresses to the internet too. +//! Its own test binary, with one test in order: it fills the process-wide record, which would hold +//! every other test's addresses to the internet too. use rustgis_engine::map as rustgis_map; use rustgis_engine::render::rustgis_tiles::{address::Reach, cache}; @@ -25,17 +26,32 @@ fn held(dates: usize) -> String { } #[test] -fn a_project_that_fills_the_record_of_held_addresses_says_so() { - let said = |s: &Session| s.notices_since(0).iter().filter(|n| n.text.contains("filled the record")).count(); +fn a_full_record_of_held_addresses_is_said_and_keeps_what_was_marked() { + let full = |s: &Session| s.notices_since(0).iter().filter(|n| n.text.contains("filled the record")).count(); + let unmarked = |text: &str| text.contains("only because this session's record of such addresses is full"); // Within the record: nothing said, and the user's own addresses are theirs. let opened = Session::new(Project::from_json(&held(10)).unwrap()); - assert_eq!(said(&opened), 0); + assert_eq!(full(&opened), 0); + let (_, report) = opened.project.clone().saved_text(None).unwrap(); + assert!(!report.notices().iter().any(|n| unmarked(n)), "nothing said with room in the record"); assert!(!cache::public_restrictions_full()); assert_eq!(cache::ceiling_for("http://192.168.1.5/tiles/0/0/0.png"), Reach::Local); // Past it (a data cube with more dated files than the record holds): said once, and from then // on every address is held to the internet. let opened = Session::new(Project::from_json(&held(rustgis_map::tiles::MAX_TIME_URLS)).unwrap()); - assert_eq!(said(&opened), 1, "{:?}", opened.notices_since(0).iter().map(|n| &n.text).collect::>()); + assert_eq!(full(&opened), 1, "{:?}", opened.notices_since(0).iter().map(|n| &n.text).collect::>()); assert!(cache::public_restrictions_full()); assert_eq!(cache::ceiling_for("http://192.168.1.5/tiles/0/0/0.png"), Reach::Public); + // A layer read marked keeps its mark, though the record has no room for its addresses; one + // added since, held only because the record is full, is written unmarked, and that is said. + let mut s = Session::new(Project::from_json(&held(7)).unwrap()); + s.run("map.addTiles", &json!({"url": "https://after-full.example/{z}/{x}/{y}.png", "name": "Later", "overlay": true})).unwrap(); + let (text, report) = s.project.saved_text(None).unwrap(); + let v: serde_json::Value = serde_json::from_str(&text).unwrap(); + let marked = |name: &str| v["maps"][0]["tiles"].as_array().unwrap().iter().any(|t| t["name"] == name && t["internetOnly"] == true); + assert!(marked("Scene"), "read marked, kept marked"); + assert!(!marked("Later")); + let said: Vec = report.notices().into_iter().filter(|n| unmarked(n)).collect(); + assert_eq!(said.len(), 1, "{:?}", report.notices()); + assert!(said[0].starts_with("1 layer(s)"), "{said:?}"); } diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index d83aa95cb9..b5c98a3934 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -565,6 +565,12 @@ fn direct_base_origin(url: &str, from: Option<&crate::address::Origin>) -> Optio Some(crate::address::Origin { url: origin, reach: crate::address::Reach::Public }) } +/// Whether the user has named `url` directly since a document did ([`allow_named`]). +pub fn named_by_user(url: &str) -> bool { + let base = canonical_resource(url); + !base.is_empty() && public_only().lock().unwrap_or_else(|e| e.into_inner()).named_local.contains(base) +} + /// Clears any document-origin restriction on `url` when the user explicitly names it directly. pub fn allow_named(url: &str) { let base = canonical_resource(url); From 896609db7afe661143707c6d355971fca18d06dc Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 23 Nov 2026 16:52:21 -0600 Subject: [PATCH 7/7] fix(project): say when a layer held as a whole holds addresses the user named A layer marked while the user has named some of its addresses is written marked, and writing it says that those addresses are held to the internet again when it is read. docs/maintaining.md states this and the exception for layers held only by a full record. --- crates/engine/src/cmd/items.rs | 21 ++------ crates/engine/src/durable.rs | 5 ++ crates/engine/src/project.rs | 88 ++++++++++++++++++++++++++-------- docs/maintaining.md | 9 +++- 4 files changed, 85 insertions(+), 38 deletions(-) diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index 63f0ddb6cb..b8d183a333 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -847,8 +847,7 @@ fn package_project(s: &mut Session, notes: &mut rustgis_data::loss::Notes) -> Re // Offline areas are maps too, and their copies keep a streamed layer's source and the tiles. let linked = left_linked("Package Project", p.maps.iter().chain(p.offline_areas.iter().map(|a| &a.data))); // What documents read from the internet named stays held there when the package is read. - let held = p.mark_internet_only(); - say_held_unmarked(s, held); + p.mark_internet_only().say(s); let name = p.name.clone(); let readme = format!("{} — a RustGIS project package.\nOpen it with RustGIS (Project › Open), or unzip it for {}.rgis.\n", name, name); // The package as unzipped, the README with it, within what a zip and a project may hold. @@ -931,7 +930,7 @@ fn package_map(s: &mut Session, mobile: bool, tol: f64, linked: &mut rustgis_dat let name = m.name.clone(); // With the map file's header, so an older reader refuses what it can't draw. let (bytes, mut report) = crate::durable::output_owned(m, crate::project::map_file_bytes)?; - report.held_unmarked = u32::try_from(held).unwrap_or(u32::MAX); + held.report(&mut report); crate::durable::notify(s, &report); let kind = if mobile { "mobile map package" } else { "map package" }; let readme = format!("{} — a RustGIS {kind}.\nAdd it to a project with Data › Import.\n", name); @@ -1836,8 +1835,7 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve crate::project::ensure_map_imports_complete(map)?; let mut map = embedded_map(map, &mut MAX_EMBED.clone()); // What documents read from the internet named stays held there when the file is read. - let held = crate::project::mark_internet_only(&mut map); - say_held_unmarked(s, held); + crate::project::mark_internet_only(&mut map).say(s); let name = map.name.clone(); (name, durable_bytes_with(s, map, crate::project::map_file_bytes)?) } @@ -1848,8 +1846,7 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve return Err("this layer is still downloading; wait for it to finish before saving".into()); } let mut layer = embed_layer(l, &mut MAX_EMBED.clone()); - let held = crate::project::mark_layer_internet_only(&mut layer); - say_held_unmarked(s, usize::from(held)); + crate::project::mark_layer_internet_only(&mut layer).say(s); let name = layer.name.clone(); (name, durable_bytes_with(s, layer, crate::project::layer_file_bytes)?) } @@ -1872,8 +1869,7 @@ pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Ve t.name = super::within("name", "a template's name", n, 200)?; } // What documents read from the internet named stays held there when it is used. - let held = t.mark_internet_only(); - say_held_unmarked(s, held); + t.mark_internet_only().say(s); let name = t.name.clone(); let bytes = durable_bytes(s, t)?; if source_references > 0 { @@ -1976,13 +1972,6 @@ pub(crate) fn save_item(s: &mut Session, kind: &str, p: &Value) -> CmdResult { } /// Consumes the existing item draft, emitting losses after serialization has completed. -/// Says how many layers held to the internet only by a full record were written without the hold. -fn say_held_unmarked(s: &mut Session, held: usize) { - if held > 0 { - s.notify(format!("{held} {}", crate::project::HELD_UNMARKED), false); - } -} - fn durable_bytes(s: &mut Session, value: T) -> Result, String> { durable_bytes_with(s, value, to_json) } diff --git a/crates/engine/src/durable.rs b/crates/engine/src/durable.rs index 9e8255c271..65737b5171 100644 --- a/crates/engine/src/durable.rs +++ b/crates/engine/src/durable.rs @@ -30,6 +30,9 @@ pub struct Report { /// Layers held to the internet only because the session's record of such addresses is full, /// written without the hold ([`crate::project::HELD_UNMARKED`]). pub(crate) held_unmarked: u32, + /// Layers written held to the internet as a whole though the user named some of their + /// addresses ([`crate::project::NAMED_HELD`]). + pub(crate) named_held: u32, } impl Report { @@ -76,6 +79,7 @@ impl Report { (self.lost, "address(es) lost their keys when a peer sent back its project; add them again in the receiving session"), (self.reconnect, "database source(s) from a peer require an explicit reconnect before reading"), (self.held_unmarked, crate::project::HELD_UNMARKED), + (self.named_held, crate::project::NAMED_HELD), ( self.executable_changes, "credential-bearing executable field(s) changed when a peer sent back its project; supply missing values before replay", @@ -124,6 +128,7 @@ impl Report { self.reconnect = self.reconnect.saturating_add(other.reconnect); self.numbers = self.numbers.saturating_add(other.numbers); self.held_unmarked = self.held_unmarked.saturating_add(other.held_unmarked); + self.named_held = self.named_held.saturating_add(other.named_held); for place in &other.number_places { if self.number_places.len() < 3 && !self.number_places.contains(place) { self.number_places.push(place.clone()); diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index ac8cd72586..f2b03dd24b 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1871,10 +1871,10 @@ impl Project { } /// Marks every map's layers held to the internet ([`mark_internet_only`]), before writing; - /// returns how many are held only by a full record, and written without the hold. - pub(crate) fn mark_internet_only(&mut self) -> usize { + /// returns what that leaves to say. + pub(crate) fn mark_internet_only(&mut self) -> Marked { let maps = self.maps.iter_mut().chain(self.offline_areas.iter_mut().map(|a| &mut a.data)); - maps.map(mark_internet_only).sum() + maps.map(mark_internet_only).fold(Marked::default(), Marked::add) } /// Writes controlled durable fields and relative paths in one guarded transaction. Live @@ -1887,7 +1887,7 @@ impl Project { let unrecorded = self.bound_address_losses(false); let (text, mut report) = crate::durable::output_remembered(self, dir.and_then(Path::to_str), project_text)?; report.addresses = report.addresses.saturating_add(u32::try_from(unrecorded).unwrap_or(u32::MAX)); - report.held_unmarked = u32::try_from(held).unwrap_or(u32::MAX); + held.report(&mut report); Ok((text, report)) } @@ -1915,7 +1915,7 @@ impl Project { json_within(p, max)?.ok_or_else(|| format!("the project is too large to keep a recovery copy (maximum {})", limit_said(max))) })?; report.addresses = report.addresses.saturating_add(u32::try_from(unrecorded).unwrap_or(u32::MAX)); - report.held_unmarked = u32::try_from(held).unwrap_or(u32::MAX); + held.report(&mut report); Ok((text, report)) } @@ -2985,6 +2985,40 @@ pub(crate) fn held_full_notice(place: &str) -> String { /// on every address is held there. pub(crate) const HELD_FULL: &str = "holding the layers whose addresses came from documents read from the internet filled the record of such addresses {when} (in {places}): until RustGIS is restarted, every address is held to the internet, and services on this computer or the local network can't be reached"; +/// What is said when layers held to the internet as a whole are written though the user named some +/// of their addresses, after their count. +pub(crate) const NAMED_HELD: &str = "layer(s) were written held to the internet as a whole, though you named some of their addresses yourself: opened again, those addresses are held there too; add them again to reach them on this computer or the local network"; + +/// What marking layers before they are written leaves to say ([`mark_internet_only`]). +#[derive(Clone, Copy, Debug, Default)] +pub(crate) struct Marked { + /// Held to the internet only by a full record, written unmarked ([`HELD_UNMARKED`]). + unmarked: usize, + /// Written marked though the user named some of their addresses ([`NAMED_HELD`]). + named: usize, +} + +impl Marked { + fn add(self, other: Marked) -> Marked { + Marked { unmarked: self.unmarked.saturating_add(other.unmarked), named: self.named.saturating_add(other.named) } + } + + /// Counts it in the output's report, which says it. + pub(crate) fn report(self, report: &mut crate::durable::Report) { + report.held_unmarked = u32::try_from(self.unmarked).unwrap_or(u32::MAX); + report.named_held = u32::try_from(self.named).unwrap_or(u32::MAX); + } + + /// Says it, one notice for each kind. + pub(crate) fn say(self, s: &mut crate::Session) { + for (n, text) in [(self.unmarked, HELD_UNMARKED), (self.named, NAMED_HELD)] { + if n > 0 { + s.notify(format!("{n} {text}"), false); + } + } + } +} + /// What is said when layers held to the internet only by a full record are written without the /// hold, after their count. pub(crate) const HELD_UNMARKED: &str = "layer(s) held to the internet only because this session's record of such addresses is full were written without the hold: opened again, their addresses are read as your own"; @@ -2998,34 +3032,42 @@ pub(crate) const HELD_UNMARKED: &str = "layer(s) held to the internet only becau /// addresses come from one document (a tile layer's template, legends and dated steps from its /// capabilities or tile set; a map layer's sources from the one add): it is marked while any of /// them is recorded, so a legend a document named stays held though the user has named the -/// template since, and the rest narrow with it. +/// template since, and the rest narrow with it: that is said ([`NAMED_HELD`]), since the addresses +/// the user named are held to the internet again when the map is read. /// -/// Returns how many layers are held to the internet now only because the record is full (added -/// after it filled, so nothing recorded them) and are written unmarked, for the caller to say. +/// Returns, for the caller to say, how many layers are held to the internet now only because the +/// record is full (added after it filled, so nothing recorded them) and are written unmarked, and +/// how many are written marked though the user named some of their addresses. /// /// [`cache::recorded_public`]: crate::render::rustgis_tiles::cache::recorded_public /// [`cache::named_by_user`]: crate::render::rustgis_tiles::cache::named_by_user -pub(crate) fn mark_internet_only(map: &mut Map) -> usize { +pub(crate) fn mark_internet_only(map: &mut Map) -> Marked { use crate::render::rustgis_tiles::cache; let web = |a: &&str| rustgis_map::tiles::is_web(a); - let mut held = 0; + let mut marked = Marked::default(); for tile in &mut map.tiles { - tile.internet_only = - tile.addresses().any(cache::recorded_public) || (tile.internet_only && !tile.addresses().filter(web).any(cache::named_by_user)); - held += usize::from(held_by_full_record(tile.internet_only, tile.addresses().filter(web))); + let named = tile.addresses().filter(web).any(cache::named_by_user); + tile.internet_only = tile.addresses().any(cache::recorded_public) || (tile.internet_only && !named); + marked = marked.add(Marked { + unmarked: usize::from(held_by_full_record(tile.internet_only, tile.addresses().filter(web))), + named: usize::from(tile.internet_only && named), + }); } for layer in &mut map.layers { - held += usize::from(mark_layer_internet_only(layer)); + marked = marked.add(mark_layer_internet_only(layer)); } - held + marked } -/// [`mark_internet_only`] for one layer; true when it is held only by a full record and is written -/// unmarked. -pub(crate) fn mark_layer_internet_only(layer: &mut rustgis_map::Layer) -> bool { +/// [`mark_internet_only`] for one layer. +pub(crate) fn mark_layer_internet_only(layer: &mut rustgis_map::Layer) -> Marked { use crate::render::rustgis_tiles::cache; - layer.internet_only = layer_recorded(layer) || (layer.internet_only && !layer_web_addresses(layer).any(cache::named_by_user)); - held_by_full_record(layer.internet_only, layer_web_addresses(layer)) + let named = layer_web_addresses(layer).any(cache::named_by_user); + layer.internet_only = layer_recorded(layer) || (layer.internet_only && !named); + Marked { + unmarked: usize::from(held_by_full_record(layer.internet_only, layer_web_addresses(layer))), + named: usize::from(layer.internet_only && named), + } } /// Whether an unmarked layer with these web addresses is held to the internet now only because the @@ -3218,12 +3260,16 @@ mod internet_only_tests { v["maps"][0]["tiles"].as_array().unwrap().iter().any(|t| t["name"] == name && t["internetOnly"] == true) }; // The template named, its legend still came from the document: held whole. + // The template it names is held there again when reopened, and that is said. cache::allow_named(&template); - let (named_template, _) = s.project.saved_text(None).unwrap(); + let (named_template, report) = s.project.saved_text(None).unwrap(); assert!(marked(&named_template, "Roads"), "its legend is still the document's"); + let said = report.notices().into_iter().filter(|n| n.contains("though you named some of their addresses")).collect::>(); + assert!(said.len() == 1 && said[0].starts_with("1 layer(s)"), "{said:?}"); forget(&addresses); let reopened = Session::new(Project::from_json(&named_template).unwrap()); assert_eq!(cache::ceiling_for(&legend), Reach::Public); + assert_eq!(cache::ceiling_for(&template), Reach::Public, "held as a whole"); drop(reopened); // Every address of it named: saved unmarked. cache::restrict_to_public(&style); diff --git a/docs/maintaining.md b/docs/maintaining.md index 4cb970b2f0..e029112a9f 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -160,7 +160,14 @@ with both needs nothing: an older RustGIS refuses it when it runs. Projects, map files and layer files with a layer held to the internet (one whose addresses a document read from the internet named: `internetOnly` on a tile layer, `internet_only` on a map layer) require `internet-only`, so an older reader refuses them instead of reading the layer's -addresses wherever their names resolve and saving the project again without the hold. +addresses wherever their names resolve and saving the project again without the hold. The one +exception is a layer held only because the session's record of such addresses is full (one added +after it filled): it is written unmarked, so its file needs nothing new and opening it again +doesn't hold it, and writing it says so. + +A layer is held or not as a whole: one marked because some of its addresses came from such a +document holds every address it has when it is read, including any the user named since, and +writing it says so. Projects, map files and layer files with a label class curved along a guide line layer (`labels.placement` with a `guide`) require `label-guide`, so an older reader refuses them instead