mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 09:46:19 +01:00
Scripts: queued startup runs keep the file access scope of the request that queued them
In the app, script.startup.run starts only the first queued run inside the request; the later startup scripts and the chosen script start from the frame loop. Each of them now starts, and its file is read, in the scope captured when the queue was built, so a confined request's automation roots apply to every run it queued.
This commit is contained in:
1 parent
81dfbf4078
commit
909c169afe
5 files changed
+41
-2
No files matched your search
@@ -449,17 +449,20 @@ impl Session {
|
||||
pub(crate) fn start_queued(&mut self) -> Option<Value> {
|
||||
// Held aside while a run starts, so that the queue does not count as a running script then.
|
||||
let mut queue = std::mem::take(&mut self.script_queue);
|
||||
// Each run starts in the file access scope of the request that queued it, which the run
|
||||
// keeps, and not in the scope of the frame that starts it.
|
||||
let scope = self.script_queue_scope.clone().unwrap_or_else(crate::file_access::ScopeHandle::capture);
|
||||
let mut reply = None;
|
||||
while self.script_key.is_none() {
|
||||
let Some(next) = queue.pop_front() else { break };
|
||||
match next {
|
||||
script::startup::Queued::Startup { path, fuel } => {
|
||||
if let Err(e) = self.start_startup(&path, fuel) {
|
||||
if let Err(e) = scope.clone().run(|| self.start_startup(&path, fuel)) {
|
||||
self.startup_failures.push((file_name_of(&path), e));
|
||||
}
|
||||
}
|
||||
script::startup::Queued::Then(params) => {
|
||||
match run(self, ¶ms) {
|
||||
match scope.clone().run(|| run(self, ¶ms)) {
|
||||
Ok(_) if self.script_key.is_some() => {}
|
||||
Ok(v) => reply = Some(v),
|
||||
Err(e) => self.startup_failures.push((then_name(¶ms), e.to_string())),
|
||||
@@ -468,6 +471,9 @@ impl Session {
|
||||
}
|
||||
}
|
||||
}
|
||||
if queue.is_empty() {
|
||||
self.script_queue_scope = None;
|
||||
}
|
||||
self.script_queue = queue;
|
||||
reply
|
||||
}
|
||||
@@ -553,6 +559,7 @@ fn startup_run(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if s.script_frames {
|
||||
s.script_queue =
|
||||
scripts.into_iter().map(|path| script::startup::Queued::Startup { path, fuel }).chain(then.map(script::startup::Queued::Then)).collect();
|
||||
s.script_queue_scope = Some(crate::file_access::ScopeHandle::capture());
|
||||
let queued = s.script_queue.len();
|
||||
s.startup_failures.clear();
|
||||
let then = s.start_queued();
|
||||
|
||||
Reference in new issue
Block a user