Skip to content
7 changes: 6 additions & 1 deletion crates/engine/src/cmd/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,10 @@ fn copy_path(s: &mut Session, p: &Value) -> CmdResult {
let path = path.ok_or_else(|| format!("{} isn't stored in a file", l.name))?;
// A service layer's address is its source: copied without keys, tokens or its password, as
// the details pane shows it and a saved project keeps a web address.
Ok(json!({"text": crate::sources::redact(&path)}))
let text = crate::sources::redact(&path);
if text != path {
// Not the layer's name: it may hold an address with a key of its own.
s.notify("The copied address leaves out part of the layer's address (keys, tokens, a password, a login or a fragment), so it may not work as it is", false);
}
Ok(json!({"text": text}))
}
6 changes: 3 additions & 3 deletions crates/engine/src/cmd/design.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,8 @@ fn polar_transform(
})
}

/// [`modify`] for a move, turn or scale, which leaves a vertex missing a coordinate where it was:
/// says how many of the features it changed have one.
/// [`modify`] for a move, turn or scale, which leaves a vertex missing a coordinate (or with an
/// infinite one) where it was: says how many of the features it changed have one.
fn move_features(s: &mut Session, mut change: impl FnMut((u32, usize), &Geometry) -> Result<Option<Geometry>, String>) -> CmdResult {
let mut missing = 0usize;
let done = modify(s, |key, g| {
Expand All @@ -953,7 +953,7 @@ fn move_features(s: &mut Session, mut change: impl FnMut((u32, usize), &Geometry
Ok(moved)
})?;
if missing > 0 {
s.warn(format!("{missing} feature(s) have a vertex missing a coordinate, which was left where it was"));
s.warn(format!("{missing} feature(s) have a vertex missing a coordinate or with an infinite one, which was left where it was"));
}
Ok(done)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn commands() -> Vec<C> {
C::new("layer.addEncodedPolyline", "Add Encoded Polyline", "Home › Add", add_encoded_polyline).roles(&[]).effects(crate::policy::Effects::NONE).params(
r#"{"polyline": "encoded polyline text" | [texts] (one line each), "precision"?: 5 (Google) | 6 (OSRM, Valhalla), "name"?: text}"#,
),
C::new("layer.addDataText", "Add Data (from text)", "Home › Add", add_data_text).roles(&[]).effects(crate::policy::Effects::NONE).params(r#"{"fileName": "name.geojson|.csv|.tsv", "text": string, "name"?: text, "x"?, "y"?, "wkt"?, "crs"?, "delimiter"? (as layer.addData, for delimited text), "layer"?, "paperSpace"? (as layer.addData, for a file of several layers)}"#),
C::new("layer.addDataText", "Add Data (from text)", "Home › Add", add_data_text).roles(&[]).effects(crate::policy::Effects::NONE).params(r#"{"fileName": "name.geojson|.csv|.tsv|.city.json (CityJSON: all its layers)", "text": string, "name"?: text, "x"?, "y"?, "wkt"?, "crs"?, "delimiter"? (as layer.addData, for delimited text; crs also for a CityJSON model that doesn't say), "layer"?, "paperSpace"? (as layer.addData, for a file of several layers)}"#),
C::new("layer.addSample", "Add Sample Data", "Home › Add › Add Data", add_sample).roles(&[]).effects(crate::policy::Effects::NONE).params(r#"{"name": "countries"|"cities"|"rivers"|"lakes"}"#),
C::new("layer.remove", "Remove", "Layers", remove).roles(&[]).effects(crate::policy::Effects::NONE)
.key("Delete")
Expand Down Expand Up @@ -3226,10 +3226,10 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult {
.and_then(Value::as_u64)
.is_some_and(|id| u32::try_from(id).ok().and_then(|id| s.map().layer(id)).is_none());
if missing || added.gone(s.map()) {
return Err(format!("{url}: the layer its download added was taken away (undone) before the command ran again"));
return Err(format!("{url}: the layer its download added was removed or undone before the command ran again"));
}
if super::plugins::fetch::table_gone(&answer, &s.project) {
return Err(format!("{url}: the table its download added was taken away (undone) before the command ran again"));
return Err(format!("{url}: the table its download added was removed or undone before the command ran again"));
}
return added.answer_now(s.map(), &answer);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ pub fn parse_arrangement(v: &Value) -> Result<Homes, String> {
let corner = o.get(*key).and_then(Value::as_str).map(str::trim).unwrap_or("");
homes[i] = CORNER_NAMES
.iter()
.position(|c| *c == corner)
.position(|c| c.eq_ignore_ascii_case(corner))
.ok_or_else(|| format!("arrangement: \"{key}\" is \"top-left\", \"top-right\", \"bottom-left\" or \"bottom-right\""))?;
}
if (0..4).any(|i| homes[..i].contains(&homes[i])) {
Expand Down Expand Up @@ -2062,7 +2062,7 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult {
_ => (format!("the {} and the {last}", rest.join(", the ")), "sit"),
};
warnings
.push(format!("{names} {verb} on what the map shows, the freer corners having gone to the others: move by hand what matters"));
.push(format!("{names} {verb} on what the map shows, the freer places having gone to the others: move by hand what matters"));
}
for (i, (a, ra)) in placed.iter().enumerate() {
for (b, rb) in placed.iter().skip(i + 1) {
Expand Down
36 changes: 22 additions & 14 deletions crates/engine/src/cmd/plugin_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,16 @@ impl UrlWaits {
}
}

/// Downloads waited for past [`REQUEST_WAIT`] land as failed, and are remembered as given up:
/// their addresses, redacted, to be said (a notice with a key in it loses what follows it).
fn expire(&mut self) -> Vec<String> {
let late: Vec<(u64, Value)> =
self.in_flight.iter().filter(|(.., at)| at.elapsed() >= REQUEST_WAIT).map(|(n, q, _)| (*n, q.clone())).collect();
/// Downloads waited for past [`REQUEST_WAIT`] by `now` land as failed, and are remembered as
/// given up: their addresses, redacted, to be said (a notice with a key in it loses what
/// follows it).
fn expire_at(&mut self, now: Instant) -> Vec<String> {
let late: Vec<(u64, Value)> = self
.in_flight
.iter()
.filter(|(.., at)| now.saturating_duration_since(*at) >= REQUEST_WAIT)
.map(|(n, q, _)| (*n, q.clone()))
.collect();
let mut addresses = Vec::new();
for (n, asked) in late {
self.land(n, Err(format!("no download in {} minutes", REQUEST_WAIT.as_secs() / 60)), Added::default());
Expand Down Expand Up @@ -867,13 +872,19 @@ impl Session {
/// what it answered this time. Its `layer.addUrl` calls answer what adding each download
/// answered. Errors are also given as notices, as for any command.
pub fn poll_plugin_retries(&mut self) -> Vec<(String, CmdResult)> {
self.poll_plugin_retries_at(Instant::now())
}

/// [`Session::poll_plugin_retries`] as at `now`: downloads waited for past [`REQUEST_WAIT`]
/// by then are given up (a test passes a later time instead of backdating the waits).
fn poll_plugin_retries_at(&mut self, now: Instant) -> Vec<(String, CmdResult)> {
self.url_waits.documents_in();
if self.plugin_retries.is_empty() {
return Vec::new();
}
// Said here too: the command may go on without it, and what it answers goes nowhere.
let minutes = REQUEST_WAIT.as_secs() / 60;
match self.url_waits.expire().as_slice() {
match self.url_waits.expire_at(now).as_slice() {
[] => {}
[url] => self.notify(format!("{url}: no download in {minutes} minutes, so its plugin command stopped waiting for it"), true),
many => self.notify(
Expand Down Expand Up @@ -1114,7 +1125,7 @@ mod tests {
s.map_mut().layers[at] = other;
s.rerun_landed = vec![(asked.clone(), answer, added)];
let e = s.run("layer.addUrl", &asked).unwrap_err();
assert!(e.contains("taken away (undone)"), "{e}");
assert!(e.contains("removed or undone"), "{e}");
// A tile layer (a GeoTIFF read in place answers its place in the list), then taken away.
let tiles = json!({"url": "https://x.org/{z}/{x}/{y}.png", "name": "T"});
let answer = s.run("map.addTiles", &tiles);
Expand All @@ -1135,15 +1146,15 @@ mod tests {
s.run("map.removeTiles", &json!({"index": moved})).unwrap();
assert!(s.map().tiles.iter().any(|t| t.name == "T2"));
let e = s.run("layer.addUrl", &asked).unwrap_err();
assert!(e.contains("taken away (undone)"), "{e}");
assert!(e.contains("removed or undone"), "{e}");
// A standalone table (a file with no geometry), then taken away.
let answer = s.run("layer.addDataText", &json!({"fileName": "sites.csv", "text": "id,street\n1,Champ de Mars\n"}));
assert!(answer.as_ref().unwrap()["table"].is_string(), "{answer:?}");
s.rerun_landed = vec![(asked.clone(), answer.clone(), Added::of(s.map(), &answer))];
assert_eq!(s.run("layer.addUrl", &asked), answer);
s.run("table.remove", &json!({"table": "sites"})).unwrap();
let e = s.run("layer.addUrl", &asked).unwrap_err();
assert!(e.contains("the table its download added was taken away (undone)"), "{e}");
assert!(e.contains("the table its download added was removed or undone"), "{e}");
}

/// A number lands only the read it was given for: a plugin's has no login, and a read that
Expand Down Expand Up @@ -1173,7 +1184,6 @@ mod tests {
/// Timeouts are one counted, redacted notice, and a real pinned command receives the failure.
#[test]
fn a_download_given_up_is_said_with_its_address() {
let Some(long_ago) = Instant::now().checked_sub(REQUEST_WAIT + Duration::from_secs(1)) else { return };
let mut s = Session::new(crate::project::Project::default());
let first = load_test_plugin("eng-slow-real");
let other = load_test_plugin("eng-slow-other");
Expand All @@ -1182,8 +1192,7 @@ mod tests {
let mark = s.notice_mark();
s.poll_plugin_retries();
assert!(s.notices_since(mark).is_empty(), "it still has time");
s.url_waits.in_flight[0].2 = long_ago;
let ran = s.poll_plugin_retries();
let ran = s.poll_plugin_retries_at(Instant::now() + REQUEST_WAIT);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
assert!(ran[0].1.is_err(), "{ran:?}");
s.poll_plugin_retries();
let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.error && n.text.contains("stopped waiting")).collect();
Expand All @@ -1199,9 +1208,8 @@ mod tests {
ask(&mut s, &first, json!({"url":"https://x.org/a.csv?token=hunter2"})).unwrap();
ask(&mut s, &other, json!({"url":"https://x.org/b.csv"})).unwrap();
let _taken = s.take_url_requests();
s.url_waits.in_flight.iter_mut().for_each(|w| w.2 = long_ago);
let mark = s.notice_mark();
s.poll_plugin_retries();
s.poll_plugin_retries_at(Instant::now() + REQUEST_WAIT);
let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.error && n.text.contains("stopped waiting")).collect();
assert_eq!(said.len(), 1, "{said:?}");
assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,6 @@ mod tests {
// A layer undone while the command waited: said, not named.
s.rerun_landed = vec![(asked.clone(), Ok(json!({"layer": 4_000_000})), Default::default())];
let e = s.run("layer.addUrl", &asked).unwrap_err();
assert!(e.contains("taken away (undone)"), "{e}");
assert!(e.contains("removed or undone"), "{e}");
}
}
26 changes: 23 additions & 3 deletions crates/engine/src/cmd/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn commands() -> Vec<C> {
let ext = Path::new(path).extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase();
let gpkg = gpkg_table(p, &ext)?;
let t = s.project.tables.get(s.table_index(p)?).ok_or("no such table")?;
let default = t.dataset.name.clone();
// Tables may retain geometry and its import losses, just as feature layers do.
let notes = rustgis_data::export_notes([(&t.dataset, t.dataset.extent())], path, Crs::LonLat);
let mut dbf_notes = Vec::new();
Expand All @@ -56,7 +57,7 @@ pub fn commands() -> Vec<C> {
s.notify(note, false);
}
let mut out = json!({"path": path});
report_table(s, path, &gpkg, table, &mut out);
report_table(s, path, &gpkg, &default, table, &mut out);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Ok(out)
}).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files))
.params(
Expand Down Expand Up @@ -91,8 +92,26 @@ pub fn gpkg_table(p: &Value, ext: &str) -> Result<GpkgTable, String> {
/// an export into an existing GeoPackage also says so, what went with a replaced table, and
/// which views and triggers elsewhere name it. Layers read in place from a replaced table read
/// it again.
fn report_table(s: &mut Session, path: &str, gpkg: &GpkgTable, table: Option<GpkgWritten>, out: &mut Value) {
fn report_table(s: &mut Session, path: &str, gpkg: &GpkgTable, default: &str, table: Option<GpkgWritten>, out: &mut Value) {
let Some(table) = table else { return };
// A new file's table is said only when it isn't the name asked for, or by default the
// layer's (a reserved name is prefixed, control characters and edge spaces dropped); one
// added to or replaced in a file is always named below.
let asked = gpkg.name.as_deref().unwrap_or(default);
if gpkg.mode == GpkgMode::NewFile && asked != table.table {
let note = if asked.trim().is_empty() {
format!("{path}: wrote the table {}, as there was no name to give it", table.table)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} else {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// Escaped: a control character in the name would otherwise reach the terminal.
let asked: String =
asked.chars().map(|c| if c.is_control() { c.escape_default().to_string() } else { c.to_string() }).collect();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
format!(
"{path}: wrote the table {} instead of '{asked}' (GeoPackage table names can't start with gpkg_, sqlite_ or rtree_, and lose control characters and edge spaces)",
Comment thread
giswqs marked this conversation as resolved.
Resolved
table.table
)
};
s.notify(note, false);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
if gpkg.mode != GpkgMode::NewFile {
let (reread, failed) =
if table.replaced { super::gpkg::reset_sources(s, Path::new(path), &table.table, true) } else { (0, Vec::new()) };
Expand Down Expand Up @@ -295,9 +314,10 @@ fn write_layer(l: &rustgis_map::Layer, path: &str, asked: Option<Crs>, gpkg: Gpk
// (layers reading a replaced table) is at hand.
let written_path = Some(path.to_string());
let path = path.to_string();
let default = ds.name.clone();
let then: Option<super::exports::Then> = table.map(|t| {
Box::new(move |s: &mut Session, out: &mut Value| {
report_table(s, &path, &gpkg, Some(t), out);
report_table(s, &path, &gpkg, &default, Some(t), out);
Ok(())
}) as super::exports::Then
});
Expand Down
4 changes: 3 additions & 1 deletion crates/engine/src/cmd/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ fn terrain(s: &mut Session, p: &Value) -> CmdResult {
if let TerrainSource::Layer(n) = &t.source
&& m.layers.iter().filter(|l| l.name.eq_ignore_ascii_case(n)).count() > 1
{
let e = format!("two layers are called '{n}': rename one, then turn Terrain on");
let e = format!(
"more than one layer is called '{n}': give the DEM a name of its own, then try again naming it (Terrain stays as it was)"
);
// A terrain that was on stays as it was.
if let Some(old) = old_terrain {
m.view.terrain = Some(old);
Expand Down
6 changes: 4 additions & 2 deletions crates/engine/src/service_logins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ pub fn request(s: &mut Session, connection: Option<&str>, url: &str) -> Result<S
return Ok(plain.to_string());
}
Some(c.clone())
} else if let Some(id) = s.database_logins.selection(WEB, &origin) {
candidates.iter().find(|c| c.id == id).map(|c| (*c).clone())
// A choice naming a connection no longer here (or no longer at this origin) is no choice:
// the sole connection left still lends its login.
} else if let Some(c) = s.database_logins.selection(WEB, &origin).and_then(|id| candidates.iter().find(|c| c.id == id)) {
Comment thread
giswqs marked this conversation as resolved.
Resolved
Some((*c).clone())
} else if candidates.len() == 1 {
candidates.first().map(|c| (*c).clone())
} else {
Expand Down
Loading
Loading