Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/data/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn step(n: usize) -> Result<()> {

/// Runs a nested writer without resetting or advancing its source's scan count. Cancellation
/// still reaches every writer check; dropping the guard restores the source probe on errors too.
pub(crate) fn without_counting<T>(run: impl FnOnce() -> T) -> T {
pub fn without_counting<T>(run: impl FnOnce() -> T) -> T {
struct CancelOnly(Arc<dyn Probe>);
impl Probe for CancelOnly {
fn cancelled(&self) -> bool {
Expand Down
9 changes: 7 additions & 2 deletions crates/engine/src/cmd/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ fn new(s: &mut Session, p: &Value) -> CmdResult {
for said in s.connections.redaction_notices_since(redactions) {
s.warn(said);
}
resolve_keys(s, &address_keys(&c.address));
resolve_origins(s, &[&c]);
// A copy running a command of its session's (#2476) only records the connection: resolving
// logins would set the process's database passwords from its own, empty, logins. Its session
// makes the connection again when the command lands, and resolves them then.
if !s.web_logins.is_borrowing() {
resolve_keys(s, &address_keys(&c.address));
resolve_origins(s, &[&c]);
}
Ok(shown_stripped(s, &c, stripped, ps(p, "address").unwrap_or(""), key_hint.as_deref()))
}

Expand Down
356 changes: 335 additions & 21 deletions crates/engine/src/cmd/qgis.rs

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion crates/engine/src/cmd/reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! delimited text or spreadsheet read whole, a ZIP or CityJSON/CityGML model's layers, the opening
//! of a large Shapefile or GeoJSON file read in place, #2446), Repair/Reload Data, Load All
//! Features, Convert To Annotation's read of a layer read in place, native models or scripts, the
//! Error Inspector's topology check (#1291), Source File State's hashing of a layer's file, Column Statistics' count of a column and Import QGIS Style's file and images. [`read_ahead`]
//! Error Inspector's topology check (#1291), Source File State's hashing of a layer's file, Column Statistics' count of a column, Import QGIS Style's file and images, and Import QGIS Project's import on a copy of the session. [`read_ahead`]
//! takes what the read needs of the session, [`ReadAhead::run`] reads on the thread, and [`read_land`]
//! runs the admitted command under its initiating owner: the command takes
//! it instead of reading again, so what it adds, says, logs and puts in Undo is the same as when
Expand Down Expand Up @@ -212,6 +212,41 @@ pub fn read_ahead(s: &mut Session, command: &str, p: &Value) -> Result<ReadAhead
s.start_read(command, p)
}

/// An import of a QGIS project's first part, which the desktop app makes on a thread of its own
/// before [`read_ahead_scanned`] (`control` stops it): its file read and parsed and the web
/// addresses its layers name found, so that the window opens their logins and starts the import
/// without reading the file. Its failure (a file that isn't a project, too large) is the import's.
/// With `log_inputs` (the session's processing log on: `Session::log`), the files it reads (the
/// project's, its markers' images) are kept for the import to log as its inputs.
#[cfg(not(target_arch = "wasm32"))]
pub fn scan_import(
p: &Value,
control: &std::sync::Arc<rustgis_analysis::control::Control>,
log_inputs: bool,
) -> Result<super::qgis::ImportScan, String> {
let mut scanned = Err(String::new());
let capture = log_inputs.then(rustgis_data::provenance::Capture::start);
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
rustgis_analysis::run_under("Import QGIS Project", control, || {
scanned = super::qgis::scan(p);
Ok(())
})
}))
.unwrap_or_else(|_| Err("Import QGIS Project failed unexpectedly".to_string()));
let inputs = capture.as_ref().map_or_else(Vec::new, rustgis_data::provenance::Capture::inputs);
res?;
scanned.map(|scan| scan.with_inputs(inputs))
}

/// [`read_ahead`] for `project.importQgis`, given the project [`scan_import`] read for `p`.
#[cfg(not(target_arch = "wasm32"))]
pub fn read_ahead_scanned(s: &mut Session, p: &Value, scan: super::qgis::ImportScan) -> Result<ReadAhead, String> {
s.import_scanned = Some(scan);
let read = s.start_read("project.importQgis", p);
s.import_scanned = None;
read
}

/// The commands whose read the desktop app makes on a thread of its own before they land
/// ([`read_ahead`]), each with what its read is called, besides the table edits
/// (`edit::TABLE_EDITS`). The cancel tests (`tests/cancellation.rs`) exercise every one, or name
Expand All @@ -237,6 +272,7 @@ pub(crate) const IN_BACKGROUND: &[(&str, &str)] = &[
("layer.sizeBy", "Size by Field"),
("offline.keepRows", "Keep Field Package Rows"),
("style.importQgis", "Import QGIS Style"),
("project.importQgis", "Import QGIS Project"),
];

/// What `command`'s read is called, when it is one the app makes before the command lands
Expand Down Expand Up @@ -331,6 +367,13 @@ pub(crate) fn prepare(s: &mut Session, op: Authorized<CommandOp>, owner: Continu
"layer.sizeBy" => (super::layer::size_by_ahead(s, params), None),
"offline.keepRows" => (super::field_changes::keep_ahead(s), None),
"style.importQgis" => (super::qgis::style_ahead(s, params), None),
"project.importQgis" => {
#[cfg(not(target_arch = "wasm32"))]
let work = super::qgis::import_ahead(s, params, owner.native_tool_owner());
#[cfg(target_arch = "wasm32")]
let work = None;
(work, None)
}
// Listed in IN_BACKGROUND without a read here.
id => return Err(not_in_background(id)),
};
Expand Down
21 changes: 19 additions & 2 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,13 @@ pub struct Session {
/// there. Its notices stay its own: the run there says them.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) requests_into: Option<rustgis_data::diagnostics::Capture>,
/// A QGIS project's import prepared for the read about to run it on a copy, its logins opened
/// before the read recorded the accounts (#2476): taken at once by that read.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) import_opened: Option<crate::cmd::qgis::ImportOpened>,
/// The project an import's first part read for it ([`cmd::reads::scan_import`]), while its read starts.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) import_scanned: Option<crate::cmd::qgis::ImportScan>,
/// The tools run ahead that a model's run took, for the tests.
#[cfg(test)]
pub(crate) tools_taken: usize,
Expand Down Expand Up @@ -1612,6 +1619,10 @@ impl Session {
zones_ahead: None,
#[cfg(not(target_arch = "wasm32"))]
requests_into: None,
#[cfg(not(target_arch = "wasm32"))]
import_opened: None,
#[cfg(not(target_arch = "wasm32"))]
import_scanned: None,
#[cfg(test)]
tools_taken: 0,
#[cfg(test)]
Expand Down Expand Up @@ -2319,9 +2330,15 @@ impl Session {
/// failed to start, or their worker failed): only the session still holds it. It goes back
/// while nothing else changed the project since, newest set aside first so the oldest ends
/// in front, and is freed and said otherwise. Run before each command run by itself, and by
/// the desktop as its background jobs end, so Undo sees it.
/// the desktop as its background jobs end, so Undo sees it. Logins opened for an import that
/// ended without landing end again here too ([`service_logins::reclaim_held`]).
pub fn reclaim_rooms(&mut self) {
if self.depth > 0 || self.rooms.is_empty() {
if self.depth > 0 {
return;
}
#[cfg(not(target_arch = "wasm32"))]
service_logins::reclaim_held(self);
if self.rooms.is_empty() {
return;
}
let (ended, running): (Vec<_>, Vec<_>) =
Expand Down
72 changes: 51 additions & 21 deletions crates/engine/src/policy/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,47 @@ impl Session {
let id = self.layer_id(&Value::Object(params.clone()))?;
params.insert("layer".into(), json!(id));
}
let mut op = self.authorize(command, &Value::Object(params))?;
self.check_read_command(&op)?;
let copy_command = matches!(command, "model.run" | "script.run") && self.policy_user();
if copy_command {
// A model's or script's native copy may read through several tools. Bind the original
// session's runtime stores, including web logins, before that copy exists.
let mut node = (*op.node).clone();
node.auth = Some(Arc::new(super::scope::RuntimeAccounts::capture(self)?));
op.node = Arc::new(node);
// A QGIS project's import runs on a copy that borrows the logins its services need: they
// are opened here, before its approval and its read record the accounts they are checked
// against (#2476).
#[cfg(not(target_arch = "wasm32"))]
{
self.import_opened = None;
if command == "project.importQgis" && self.policy_user() {
self.import_opened = crate::cmd::qgis::open_import_logins(self, &Value::Object(params.clone()));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
let node = op.node.clone();
let mut owner = self.continuation_for(node.clone())?;
if copy_command {
owner.accounts = self.policy_accounts();
owner.s3 = Some(vec![crate::render::rustgis_tiles::s3::account_identity()?]);
// The opened import is let go on every way out, refused or prepared: logins it opened end
// again unless the import holding them lands (`service_logins::reclaim_held`).
let prepared = (|s: &mut Self| -> Result<crate::cmd::reads::ReadAhead, String> {
let mut op = s.authorize(command, &Value::Object(params))?;
s.check_read_command(&op)?;
let copy_command = matches!(command, "model.run" | "script.run") && s.policy_user();
if copy_command {
// A model's or script's native copy may read through several tools. Bind the original
// session's runtime stores, including web logins, before that copy exists.
#[cfg(not(target_arch = "wasm32"))]
crate::service_logins::adopt_held(s);
let mut node = (*op.node).clone();
node.auth = Some(Arc::new(super::scope::RuntimeAccounts::capture(s)?));
op.node = Arc::new(node);
}
let node = op.node.clone();
let mut owner = s.continuation_for(node.clone())?;
if copy_command {
owner.accounts = s.policy_accounts();
owner.s3 = Some(vec![crate::render::rustgis_tiles::s3::account_identity()?]);
}
owner.check()?;
let current = owner.clone();
let still = Arc::new(move || current.check().is_ok());
s.with_node(node, |s| crate::render::rustgis_tiles::cache::with_still(still, || crate::cmd::reads::prepare(s, op, owner)))
})(self);
#[cfg(not(target_arch = "wasm32"))]
{
self.import_opened = None;
}
owner.check()?;
let current = owner.clone();
let still = Arc::new(move || current.check().is_ok());
self.with_node(node, |s| crate::render::rustgis_tiles::cache::with_still(still, || crate::cmd::reads::prepare(s, op, owner)))
prepared
}
/// Lands only the original read invocation; no result can be claimed by another command.
pub(crate) fn finish_read(&mut self, read: crate::cmd::reads::Read) -> CmdResult {
Expand All @@ -210,18 +231,26 @@ impl Session {
CommandOp::Registered { spec, params } => (spec.id, params.clone()),
_ => return Err("not a registered read command".into()),
};
// A project's import makes a map of its own: the user's own lands whichever map is shown by
// then, as a tool's project-wide output does, with every other check of its owner (#3120).
let project_wide = command == "project.importQgis" && owner.native_tool_owner();
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
self.with_deferred_downloads(|s| {
s.command_epilogue(command, &params, |s| {
rustgis_data::provenance::record(inputs);
s.check_delivery(&owner)?;
if project_wide {
s.check_delivery_owner(&owner)?;
s.check_continuation_origin(&owner)?;
} else {
s.check_delivery(&owner)?;
}
if let Some(source) = &source {
let layer = s.map().layer(s.layer_id(&params)?).ok_or("no such layer")?;
if !layer.source.as_ref().is_some_and(|current| current.same_opening(source)) {
return Err("the live source changed since this read started".into());
}
}
s.resume(&owner, |s| {
let land = |s: &mut Session| {
if !owner.native_tool_owner() && *op.node != s.command_node(command, &params)? {
return Err("the read command changed since it was authorized".into());
}
Expand All @@ -238,7 +267,8 @@ impl Session {
s.note_source(source);
}
result
})?
};
if project_wide { s.resume_checked(&owner, land) } else { s.resume(&owner, land) }?
})
})
}));
Expand Down
Loading
Loading