mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 07:49:26 +00:00
Scripts: commands read through the gate in runs the person starts, and the grants file is not written over when it cannot be read
- A command a script runs reads only where the script may, also in a run the person started; only reads of the app's own folders inside the command are exempt. - Always and script.grants.revoke leave a grants file they cannot read as it is, and fail. - script.grants names a path outside the automation read roots by its file name alone. - copy reads the source once, within the 8 MiB limit, writes those bytes, and gives the copy the source's permissions. - write joins its values as UTF-16 before making them text, so a surrogate pair split between two values is one character.
This commit is contained in:
@@ -341,7 +341,17 @@ fn list_installed(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
fn grants(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
let Some(dir) = s.script_data_dir() else { return Ok(json!({"grants": [], "file": null})) };
|
||||
let file = dir.with_file_name(script::files::GRANTS_FILE);
|
||||
Ok(json!({"grants": script::files::stored_grants(dir), "file": file.to_string_lossy()}))
|
||||
// A script or a granted path outside the automation read roots is named by its file name alone.
|
||||
let mut grants = script::files::stored_grants(dir);
|
||||
for g in &mut grants {
|
||||
for key in ["script", "path"] {
|
||||
if let Some(name) = g[key].as_str().and_then(hidden_name) {
|
||||
g[key] = json!(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
let file = file.to_string_lossy();
|
||||
Ok(json!({"grants": grants, "file": super::fileio::shown_path(&file)}))
|
||||
}
|
||||
|
||||
fn grants_revoke(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
@@ -176,7 +176,7 @@ fn with_scope<T>(scope: Option<Scope>, f: impl FnOnce() -> T) -> T {
|
||||
/// Run `f` with `roots` in force on this thread (`None`: as things stand).
|
||||
pub fn confine<T>(roots: Option<&Arc<AutomationRoots>>, f: impl FnOnce() -> T) -> T {
|
||||
match roots {
|
||||
Some(r) => with_scope(Some(Scope::Confined(r.clone())), f),
|
||||
Some(r) => with_gate_reads_exempt(false, || with_scope(Some(Scope::Confined(r.clone())), f)),
|
||||
None => f(),
|
||||
}
|
||||
}
|
||||
@@ -184,24 +184,44 @@ pub fn confine<T>(roots: Option<&Arc<AutomationRoots>>, f: impl FnOnce() -> T) -
|
||||
/// Run `f` with no roots in force on this thread: what the person at the keyboard does, and the
|
||||
/// app's own folders.
|
||||
pub fn unconfined<T>(f: impl FnOnce() -> T) -> T {
|
||||
with_scope(Some(Scope::Unconfined), f)
|
||||
with_gate_reads_exempt(true, || with_scope(Some(Scope::Unconfined), f))
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// Are reads on this thread exempt from the gate of the script command it runs? Only inside an
|
||||
/// [`unconfined`] entered after the gate was put in force ([`with_script_gate`]).
|
||||
static GATE_READS_EXEMPT: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
||||
}
|
||||
|
||||
/// Puts the exemption it replaced back when dropped (also when `f` panics).
|
||||
struct RestoreExempt(bool);
|
||||
|
||||
impl Drop for RestoreExempt {
|
||||
fn drop(&mut self) {
|
||||
GATE_READS_EXEMPT.with(|e| e.set(self.0));
|
||||
}
|
||||
}
|
||||
|
||||
fn with_gate_reads_exempt<T>(exempt: bool, f: impl FnOnce() -> T) -> T {
|
||||
let _restore = RestoreExempt(GATE_READS_EXEMPT.with(|e| e.replace(exempt)));
|
||||
f()
|
||||
}
|
||||
|
||||
/// This thread's scope, with the gate of the script command it runs, to carry to work it hands to
|
||||
/// another thread ([`ScopeHandle::run`]).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ScopeHandle(Option<Scope>, Option<Arc<ScriptGate>>);
|
||||
pub struct ScopeHandle(Option<Scope>, Option<Arc<ScriptGate>>, bool);
|
||||
|
||||
impl ScopeHandle {
|
||||
/// The scope of the calling thread.
|
||||
pub fn capture() -> Self {
|
||||
Self(SCOPE.with(|s| s.borrow().clone()), GATE.with(|g| g.borrow().clone()))
|
||||
Self(SCOPE.with(|s| s.borrow().clone()), GATE.with(|g| g.borrow().clone()), GATE_READS_EXEMPT.with(std::cell::Cell::get))
|
||||
}
|
||||
|
||||
/// Run `f` in the captured scope.
|
||||
pub fn run<T>(self, f: impl FnOnce() -> T) -> T {
|
||||
let Self(scope, gate) = self;
|
||||
with_gate(gate, || with_scope(scope, f))
|
||||
let Self(scope, gate, exempt) = self;
|
||||
with_gate(gate, || with_gate_reads_exempt(exempt, || with_scope(scope, f)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,17 +272,18 @@ fn with_gate<T>(gate: Option<Arc<ScriptGate>>, f: impl FnOnce() -> T) -> T {
|
||||
}
|
||||
|
||||
/// Runs `f`, a command a script runs, with `gate` in force on this thread: every path it reads or
|
||||
/// writes must pass the gate as well as the automation roots. Reads of the app's own folders,
|
||||
/// inside [`unconfined`], are not checked; writes there are, so a script's command does not save
|
||||
/// into the app's libraries.
|
||||
/// writes must pass the gate as well as the automation roots, also when the run itself is
|
||||
/// [`unconfined`] (one the person started). Reads of the app's own folders, inside an
|
||||
/// [`unconfined`] the command enters, are not checked; writes there are, so a script's command
|
||||
/// does not save into the app's libraries.
|
||||
pub(crate) fn with_script_gate<T>(gate: ScriptGate, f: impl FnOnce() -> T) -> T {
|
||||
with_gate(Some(Arc::new(gate)), f)
|
||||
with_gate(Some(Arc::new(gate)), || with_gate_reads_exempt(false, f))
|
||||
}
|
||||
|
||||
/// May `path` be read (or written) by the script command this thread runs? Always outside one,
|
||||
/// and for a read inside [`unconfined`].
|
||||
/// and for a read inside an [`unconfined`] the command entered.
|
||||
fn check_gate(path: &str, access: Access) -> Result<(), String> {
|
||||
if matches!(access, Access::Read) && SCOPE.with(|s| matches!(*s.borrow(), Some(Scope::Unconfined))) {
|
||||
if matches!(access, Access::Read) && GATE_READS_EXEMPT.with(std::cell::Cell::get) {
|
||||
return Ok(());
|
||||
}
|
||||
GATE.with(|g| g.borrow().clone()).map_or(Ok(()), |g| g.check(path, access))
|
||||
|
||||
@@ -431,7 +431,7 @@ impl Disk {
|
||||
}
|
||||
let (Some((script, hash)), Some(store)) = (&self.script, self.store_path()) else { return };
|
||||
let (script, code) = (shown(script), self.ran.iter().cloned().collect::<Vec<_>>());
|
||||
let mut grants = read_store(&store);
|
||||
let Ok(mut grants) = try_read_store(&store) else { return };
|
||||
for g in &mut grants {
|
||||
let ours = g["script"] == *script
|
||||
&& g["sha256"] == *hash
|
||||
@@ -565,7 +565,8 @@ impl Disk {
|
||||
/// takes its place.
|
||||
fn keep(&self, paths: &[std::path::PathBuf], write: bool, folder: bool) -> Result<(), &'static str> {
|
||||
let (Some((script, hash)), Some(store)) = (&self.script, self.store_path()) else { return Err(NO_ALWAYS) };
|
||||
let mut grants = read_store(&store);
|
||||
// A grants file that is there but cannot be read is left as it is.
|
||||
let mut grants = try_read_store(&store).map_err(|_| NOT_SAVED)?;
|
||||
let script = shown(script);
|
||||
let code: Vec<&String> = self.ran.iter().collect();
|
||||
for p in paths {
|
||||
@@ -880,15 +881,34 @@ fn read_head(real: &Path, max: usize) -> std::io::Result<Vec<u8>> {
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
/// The grants the grants file at `store` holds; none when it is missing or cannot be read.
|
||||
/// The grants the grants file at `store` holds; none when it is missing or cannot be read. A grant
|
||||
/// that is not well formed is left out.
|
||||
fn read_store(store: &Path) -> Vec<serde_json::Value> {
|
||||
let Ok(bytes) = read_head(store, MAX_STORE_BYTES) else { return Vec::new() };
|
||||
load_store(store, false).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The grants the grants file at `store` holds, to change and write back; none when it is missing,
|
||||
/// and `Err` when it is there but cannot be read, is too large, is not a grants file of this
|
||||
/// version, or holds a grant that is not well formed or more grants than may be kept, so that a
|
||||
/// change is not written over it.
|
||||
fn try_read_store(store: &Path) -> std::io::Result<Vec<serde_json::Value>> {
|
||||
load_store(store, true)
|
||||
}
|
||||
|
||||
/// The grants file at `store` read as [`read_store`] reads it, or with `strict` as
|
||||
/// [`try_read_store`] does.
|
||||
fn load_store(store: &Path, strict: bool) -> std::io::Result<Vec<serde_json::Value>> {
|
||||
let bytes = match read_head(store, MAX_STORE_BYTES) {
|
||||
Ok(bytes) => bytes,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()),
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
if bytes.len() > MAX_STORE_BYTES {
|
||||
return Vec::new();
|
||||
return Err(std::io::Error::other("the grants file is too large"));
|
||||
}
|
||||
let Ok(v) = serde_json::from_slice::<serde_json::Value>(&bytes) else { return Vec::new() };
|
||||
let v = serde_json::from_slice::<serde_json::Value>(&bytes).map_err(std::io::Error::other)?;
|
||||
if v["version"] != 1 {
|
||||
return Vec::new();
|
||||
return Err(std::io::Error::other("the grants file has another version"));
|
||||
}
|
||||
let valid = |g: &serde_json::Value| {
|
||||
g["script"].is_string()
|
||||
@@ -898,7 +918,14 @@ fn read_store(store: &Path) -> Vec<serde_json::Value> {
|
||||
&& g["write"].is_boolean()
|
||||
&& g["folder"].is_boolean()
|
||||
};
|
||||
v["grants"].as_array().map(|a| a.iter().filter(|g| valid(g)).take(MAX_STORED_GRANTS).cloned().collect()).unwrap_or_default()
|
||||
if strict {
|
||||
let grants = v["grants"].as_array().ok_or_else(|| std::io::Error::other("the grants file holds no list of grants"))?;
|
||||
if grants.len() > MAX_STORED_GRANTS || !grants.iter().all(valid) {
|
||||
return Err(std::io::Error::other("the grants file holds a grant that cannot be read"));
|
||||
}
|
||||
return Ok(grants.clone());
|
||||
}
|
||||
Ok(v["grants"].as_array().map(|a| a.iter().filter(|g| valid(g)).take(MAX_STORED_GRANTS).cloned().collect()).unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Writes `grants` as the grants file at `store`: to a file beside it, which then takes its place.
|
||||
@@ -930,7 +957,7 @@ pub(crate) fn stored_grants(data_dir: &Path) -> Vec<serde_json::Value> {
|
||||
/// → how many were removed.
|
||||
pub(crate) fn revoke_grants(data_dir: &Path, script: Option<&str>, path: Option<&str>) -> std::io::Result<usize> {
|
||||
let store = data_dir.with_file_name(GRANTS_FILE);
|
||||
let grants = read_store(&store);
|
||||
let grants = try_read_store(&store)?;
|
||||
let before = grants.len();
|
||||
let kept: Vec<serde_json::Value> =
|
||||
grants.into_iter().filter(|g| !(script.is_none_or(|s| g["script"] == *s) && path.is_none_or(|p| g["path"] == *p))).collect();
|
||||
@@ -1636,28 +1663,33 @@ fn copy(host: &Host, a: &[Data]) -> Result<Data, HostError> {
|
||||
if let Err(m) = ids.iter().try_for_each(|id| disk.flush(*id)) {
|
||||
return Ok(error(m));
|
||||
}
|
||||
let n = std::fs::metadata(&source).map_or(0, |m| m.len());
|
||||
if n > MAX_FILE_BYTES as u64 {
|
||||
return Ok(error(TOO_LARGE));
|
||||
}
|
||||
// The bytes are read once, no more than the limit, and those bytes are what is charged and
|
||||
// written: a source that grows after it is read does not copy more.
|
||||
let copied = match read_head(&source, MAX_FILE_BYTES) {
|
||||
Ok(bytes) if bytes.len() > MAX_FILE_BYTES => return Ok(error(TOO_LARGE)),
|
||||
Ok(bytes) => bytes,
|
||||
Err(_) => return Ok(error(READ_FAILED)),
|
||||
};
|
||||
// The target's open objects each take a copy of the bytes, which count as written too, as does
|
||||
// the copy itself when it is written.
|
||||
let holders = disk.open.values().filter(|o| o.target.as_deref() == Some(target.as_path())).count();
|
||||
disk.charge_write(usize::try_from(n).unwrap_or(usize::MAX).saturating_mul(holders.saturating_add(usize::from(!itself))))?;
|
||||
let r = if itself { Ok(n) } else { std::fs::copy(&source, &target) };
|
||||
disk.charge_write(copied.len().saturating_mul(holders.saturating_add(usize::from(!itself))))?;
|
||||
// The copy takes the source's permissions, as `std::fs::copy` gives them.
|
||||
let permissions = std::fs::metadata(&source).map(|m| m.permissions());
|
||||
let r =
|
||||
if itself { Ok(()) } else { std::fs::write(&target, &copied).and_then(|()| permissions.and_then(|p| std::fs::set_permissions(&target, p))) };
|
||||
if !itself && (r.is_ok() || target.exists()) {
|
||||
disk.wrote(&target);
|
||||
}
|
||||
// Open objects of the target hold the copy, so closing them does not write their older bytes.
|
||||
if r.is_ok() && disk.open.values().any(|o| o.target.as_deref() == Some(target.as_path())) {
|
||||
let copied = read_head(&target, MAX_FILE_BYTES).unwrap_or_default();
|
||||
if r.is_ok() {
|
||||
for file in disk.open.values_mut().filter(|o| o.target.as_deref() == Some(target.as_path())) {
|
||||
file.bytes.clone_from(&copied);
|
||||
file.pos = file.pos.min(copied.len());
|
||||
file.dirty = false;
|
||||
}
|
||||
}
|
||||
Ok(done(r.map(drop).map_err(|_| WRITE_FAILED)))
|
||||
Ok(done(r.map_err(|_| WRITE_FAILED)))
|
||||
}
|
||||
|
||||
/// `remove(path)`: the file, or the folder when it is empty; a link itself, never what it leads to.
|
||||
|
||||
@@ -730,6 +730,34 @@ fn script_file_copy_of_an_open_file_has_its_changes() {
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// `copy` gives the copy the source's permissions: the copy of a read-only file is read-only.
|
||||
#[test]
|
||||
fn script_file_copy_keeps_the_source_read_only() {
|
||||
let base = folder("copyreadonly");
|
||||
let r = run(
|
||||
&base,
|
||||
"var d = Folder.temp.fsName, s = new File(d + '/s.txt'); s.open('w'); s.write('x'); s.close(); s.readonly = true;\n\
|
||||
var out = [s.copy(d + '/t.txt'), new File(d + '/t.txt').readonly, new File(d + '/t.txt').length];\n\
|
||||
s.readonly = false; new File(d + '/t.txt').readonly = false; vc.log(out);",
|
||||
);
|
||||
assert_eq!(r["log"], json!([[true, true, 1]]));
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// `write` with several values joins them before making them text, so a surrogate pair split
|
||||
/// between two values is written as one character.
|
||||
#[test]
|
||||
fn script_file_write_joins_a_surrogate_pair_split_between_values() {
|
||||
let base = folder("surrogates");
|
||||
let r = run(
|
||||
&base,
|
||||
"var f = new File(Folder.temp.fsName + '/s.txt'); f.encoding = 'UTF-8'; f.open('w'); f.write('\\uD83D', '\\uDE00'); f.close();\n\
|
||||
f.open('r'); var t = f.read(); f.close(); vc.log([t === '\\uD83D\\uDE00', t.length]);",
|
||||
);
|
||||
assert_eq!(r["log"], json!([[true, 2]]));
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// A grant that would make the grants file larger than it may be read is not kept, and the grants
|
||||
/// file keeps the grants it had.
|
||||
#[test]
|
||||
@@ -754,6 +782,34 @@ fn script_file_grants_file_stays_within_its_size_limit() {
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// A grants file that is there but cannot be read (another version, not JSON, a grant that is not
|
||||
/// well formed, or no list of grants) is not written over: a grant picked with Always is not kept, and a revoke fails, so the grants it holds stay.
|
||||
#[test]
|
||||
fn script_file_grants_file_that_cannot_be_read_is_left_as_it_is() {
|
||||
let cases = [
|
||||
("newer", br#"{"version": 2, "grants": [{"script": "x"}]}"#.as_slice()),
|
||||
("broken", b"{ not json".as_slice()),
|
||||
("malformed", br#"{"version": 1, "grants": [{"script": "x"}]}"#.as_slice()),
|
||||
("nolist", br#"{"version": 1, "grants": {}}"#.as_slice()),
|
||||
];
|
||||
for (name, held) in cases {
|
||||
let base = folder(&format!("store-{name}"));
|
||||
let out = base.join("picked/out.txt");
|
||||
std::fs::create_dir_all(out.parent().unwrap()).unwrap();
|
||||
let store = base.join("settings/Script Grants.json");
|
||||
write(&store, held);
|
||||
let mut s = with_data(&base);
|
||||
start_framed(&mut s, &base, "var f = File.saveDialog('p'); vc.log(f === null ? null : f.fsName);");
|
||||
assert!(pump_to_picker(&mut s).is_none());
|
||||
assert!(s.script_pick(crate::script::files::PickAnswer::Allow { paths: vec![out.to_string_lossy().into_owned()], always: true }));
|
||||
let _ = pump_to_picker(&mut s).unwrap();
|
||||
assert_eq!(std::fs::read(&store).unwrap(), held, "{name}: the grants file is left as it was");
|
||||
assert!(s.execute("script.grants.revoke", &json!({"all": true})).is_err(), "{name}");
|
||||
assert_eq!(std::fs::read(&store).unwrap(), held, "{name}: a revoke leaves it too");
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
}
|
||||
|
||||
/// `copy` of a file over 8 MiB is refused, as opening one is.
|
||||
#[test]
|
||||
fn script_file_copy_is_held_to_the_file_limit() {
|
||||
@@ -1387,6 +1443,12 @@ fn script_file_dialog_grants_are_kept_for_the_same_script_text() {
|
||||
let grants = s.execute("script.grants", &json!({})).unwrap();
|
||||
assert_eq!(grants["grants"].as_array().unwrap().len(), 1, "{grants}");
|
||||
assert_eq!(grants["grants"][0]["write"], true);
|
||||
// Under automation read roots, a path outside them is named by its file name alone.
|
||||
let roots = AutomationRoots::new(&[&base.join("main")], &[]).unwrap();
|
||||
let hidden = confine(roots.as_ref(), || s.execute("script.grants", &json!({}))).unwrap();
|
||||
assert_eq!(hidden["grants"][0]["path"], "out.txt", "{hidden}");
|
||||
assert_eq!(hidden["grants"][0]["script"], grants["grants"][0]["script"], "the script inside the roots is named whole: {hidden}");
|
||||
assert_eq!(hidden["file"], "Script Grants.json", "{hidden}");
|
||||
|
||||
start_framed(&mut s, &base, &text);
|
||||
let r = pump_to_picker(&mut s).unwrap().unwrap();
|
||||
|
||||
@@ -316,7 +316,8 @@ fn an_export_that_fails_names_no_file() {
|
||||
}
|
||||
|
||||
/// The commands a script runs read and write only where its `File` and `Folder` objects may (its
|
||||
/// temporary folder and what a person allowed it, here), and the files of the open documents.
|
||||
/// temporary folder and what a person allowed it, here), and the files of the open documents,
|
||||
/// also in a run the person started.
|
||||
#[test]
|
||||
fn a_scripts_commands_reach_only_its_own_places_and_the_open_documents() {
|
||||
let dir = fresh_folder("gate");
|
||||
@@ -354,6 +355,9 @@ fn a_scripts_commands_reach_only_its_own_places_and_the_open_documents() {
|
||||
let r = run(&mut s, &source).unwrap();
|
||||
assert_eq!(r["log"], json!(["ok", "ok", "denied", "denied"]), "an open document's own file, and no other: {r}");
|
||||
assert!(!outside.join("other.svg").exists());
|
||||
let source = format!("{}{}", call("document.open", &own), call("document.open", &outside.join("copy.svg")));
|
||||
let r = crate::file_access::unconfined(|| run(&mut s, &source)).unwrap();
|
||||
assert_eq!(r["log"], json!(["ok", "denied"]), "a run the person starts reads through the gate as well: {r}");
|
||||
std::fs::remove_file(&own).unwrap();
|
||||
let r = run(&mut s, &call("document.save", &own)).unwrap();
|
||||
assert_eq!(r["log"], json!(["ok"]), "a document's own file that was removed is made again: {r}");
|
||||
|
||||
@@ -542,19 +542,21 @@ fn write_values(i: &mut Interp, this: &Value, args: &[Value], what: &str, line:
|
||||
Value::Number(n) if n.is_finite() && n >= 0.0 => (n as usize).saturating_mul(2),
|
||||
_ => usize::MAX,
|
||||
};
|
||||
let mut text = String::new();
|
||||
let mut units = 0usize;
|
||||
// The values are joined as UTF-16 code units and made text once, so a surrogate pair split
|
||||
// between two values is one character.
|
||||
let mut joined: Vec<u16> = Vec::new();
|
||||
for a in args {
|
||||
i.use_fuel()?;
|
||||
let s = i.to_str(a)?;
|
||||
units = units.saturating_add(s.len());
|
||||
if units > max {
|
||||
if joined.len().saturating_add(s.len()) > max {
|
||||
let m = message(i, "tooLarge")?;
|
||||
set_slot(i, o, ERROR, m)?;
|
||||
return Ok(Value::Bool(false));
|
||||
}
|
||||
text.push_str(&s.to_rust_string());
|
||||
joined.extend_from_slice(&s.flat());
|
||||
}
|
||||
let mut text = String::from_utf16_lossy(&joined);
|
||||
drop(joined);
|
||||
if line {
|
||||
text.push_str(line_end(i, o)?);
|
||||
}
|
||||
|
||||
@@ -553,10 +553,18 @@ fn enter_in_a_scripts_file_dialog_denies() {
|
||||
assert_eq!(app.session.script_report().unwrap()["log"], json!([null]));
|
||||
}
|
||||
|
||||
/// Enter on the file dialog's focused Choose… button goes to that button and does not deny.
|
||||
/// Enter on the file dialog's focused Choose… button goes to that button, which opens the folder
|
||||
/// picker once, and does not deny.
|
||||
#[test]
|
||||
fn enter_on_a_focused_choose_button_does_not_deny() {
|
||||
let mut app = app();
|
||||
let asked = std::rc::Rc::new(std::cell::Cell::new(0usize));
|
||||
let counted = asked.clone();
|
||||
let pick_folder: Box<dyn FnMut() -> Option<String>> = Box::new(move || {
|
||||
counted.set(counted.get() + 1);
|
||||
None
|
||||
});
|
||||
let mut app = VectorcraftApp::new(Session::new(), crate::Services { pick_folder: Some(pick_folder), ..Default::default() });
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.session.prefs.show_external_script_warning = false;
|
||||
menus::run_ui_command(&mut app, "ui.runScript", &json!({ "source": "vc.log(Folder.selectDialog('Pick'));" })).unwrap().unwrap();
|
||||
script_runs::poll(&mut app);
|
||||
@@ -571,8 +579,10 @@ fn enter_on_a_focused_choose_button_does_not_deny() {
|
||||
frame(&mut app, events);
|
||||
}
|
||||
assert!(ctx.memory(|m| m.focused().is_some()), "Tab gives a button the keyboard focus");
|
||||
assert_eq!(asked.get(), 0);
|
||||
frame(&mut app, vec![key(egui::Key::Enter)]);
|
||||
frame(&mut app, vec![]);
|
||||
assert_eq!(asked.get(), 1, "Enter chose the focused Choose… button");
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(dialogs::script_run::PICKER_KIND), "the dialog stays open");
|
||||
assert!(app.session.script_picker().is_some(), "the run still waits");
|
||||
dialogs::cancel(&mut app);
|
||||
|
||||
+6
-4
@@ -2263,7 +2263,7 @@ The help page's writing members work as it describes
|
||||
- `open('w')` empties the file, or makes it, `open('e')` opens a file that is there, and `open('a')` opens it at its
|
||||
end. `write(...values)` writes the values as `String(value)` gives them, and `writeln(...values)` adds the line end
|
||||
`lineFeed` names: CR LF for `Windows`, CR for `Macintosh` and LF for `Unix`. A byte order mark is written only
|
||||
when the script writes ``.
|
||||
when the script writes `\uFEFF`.
|
||||
- `copy(target)` copies the file to a path or a `File` and replaces a file that is there. `remove()` deletes a file,
|
||||
or a folder only when it is empty (`Script folder is not empty`), at once and without the trash. `rename(name)`
|
||||
takes a name without a folder; a name that is in use gives `Script file name is already in use`, and the object
|
||||
@@ -2345,10 +2345,12 @@ VectorCraft writes files by these rules of its own:
|
||||
the SHA-256 of each evaluated source (of its UTF-16 code units in little-endian order), `folder` true for a folder's
|
||||
grant, which covers everything in the folder (a file's grant covers its own path only, also when a folder later
|
||||
takes its place), and `file` the grants
|
||||
file's path, or `null` without a settings folder. `script.grants.revoke {script?, path?, all?}` removes the grants of
|
||||
file's path, or `null` without a settings folder. Under automation read roots, a `script`, `path` or `file` outside them
|
||||
is given as its file name alone. `script.grants.revoke {script?, path?, all?}` removes the grants of
|
||||
a script file, of a path, of both together, or with `all: true` every grant, and returns `{removed}`. While a script
|
||||
runs it is refused with the busy error, as the run keeps the grants it started with. A script cannot run either
|
||||
command.
|
||||
runs it is refused with the busy error, as the run keeps the grants it started with. A grants file that is there but
|
||||
cannot be read is left as it is: `script.grants.revoke` fails, and a grant picked with Always is not kept. A script
|
||||
cannot run either command.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"script.grants.revoke","params":{"all":true}}}
|
||||
|
||||
Reference in New Issue
Block a user