summaryrefslogtreecommitdiff
path: root/runtime/permissions/lib.rs
diff options
context:
space:
mode:
authorYazan AbdAl-Rahman <yazan.abdalrahman@exalt.ps>2024-08-20 04:20:06 +0300
committerGitHub <noreply@github.com>2024-08-20 01:20:06 +0000
commit4f49f703c10afcde7155baac2b494fa6670c0115 (patch)
treead9231735e1fc57a71e77de97dc0ac20ea9705a6 /runtime/permissions/lib.rs
parent0eba180fdbfdc19e15c743f00382d3fc79f65a10 (diff)
fix(cli): update permission prompt message for compiled binaries (#24081)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'runtime/permissions/lib.rs')
-rw-r--r--runtime/permissions/lib.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs
index b0fa9eb10..55a94d909 100644
--- a/runtime/permissions/lib.rs
+++ b/runtime/permissions/lib.rs
@@ -12,6 +12,7 @@ use deno_core::serde::Deserialize;
use deno_core::serde::Deserializer;
use deno_core::serde::Serialize;
use deno_core::serde_json;
+use deno_core::unsync::sync::AtomicFlag;
use deno_core::url;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
@@ -132,14 +133,20 @@ impl PermissionState {
}
fn error(name: &str, info: impl FnOnce() -> Option<String>) -> AnyError {
- custom_error(
- "PermissionDenied",
+ let msg = if is_standalone() {
+ format!(
+ "Requires {}, specify the required permissions during compilation using `deno compile --allow-{}`",
+ Self::fmt_access(name, info),
+ name
+ )
+ } else {
format!(
"Requires {}, run again with the --allow-{} flag",
Self::fmt_access(name, info),
name
- ),
- )
+ )
+ };
+ custom_error("PermissionDenied", msg)
}
/// Check the permission state. bool is whether a prompt was issued.
@@ -2313,6 +2320,16 @@ pub fn create_child_permissions(
Ok(worker_perms)
}
+static IS_STANDALONE: AtomicFlag = AtomicFlag::lowered();
+
+pub fn mark_standalone() {
+ IS_STANDALONE.raise();
+}
+
+pub fn is_standalone() -> bool {
+ IS_STANDALONE.is_raised()
+}
+
#[cfg(test)]
mod tests {
use super::*;