Skip to content

Commit 4f49f70

Browse files
fix(cli): update permission prompt message for compiled binaries (#24081)
Co-authored-by: David Sherret <[email protected]>
1 parent 0eba180 commit 4f49f70

File tree

9 files changed

+67
-9
lines changed

9 files changed

+67
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/mainrt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ fn load_env_vars(env_vars: &IndexMap<String, String>) {
8383
}
8484

8585
fn main() {
86+
deno_runtime::deno_permissions::mark_standalone();
8687
let args: Vec<_> = env::args_os().collect();
8788
let standalone = standalone::extract_standalone(Cow::Owned(args));
8889
let future = async move {

ext/fs/ops.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ fn map_permission_error(
6767
} else {
6868
(path.as_str(), "")
6969
};
70-
custom_error("PermissionDenied", format!("Requires {err} access to {path}{truncated}, run again with the --allow-{err} flag"))
70+
let msg = if deno_permissions::is_standalone() {
71+
format!(
72+
"Requires {err} access to {path}{truncated}, specify the required permissions during compilation using `deno compile --allow-{err}`")
73+
} else {
74+
format!(
75+
"Requires {err} access to {path}{truncated}, run again with the --allow-{err} flag")
76+
};
77+
custom_error("PermissionDenied", msg)
7178
}
7279
err => Err::<(), _>(err)
7380
.context_path(operation, path)

runtime/permissions/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use deno_core::serde::Deserialize;
1212
use deno_core::serde::Deserializer;
1313
use deno_core::serde::Serialize;
1414
use deno_core::serde_json;
15+
use deno_core::unsync::sync::AtomicFlag;
1516
use deno_core::url;
1617
use deno_core::url::Url;
1718
use deno_core::ModuleSpecifier;
@@ -132,14 +133,20 @@ impl PermissionState {
132133
}
133134

134135
fn error(name: &str, info: impl FnOnce() -> Option<String>) -> AnyError {
135-
custom_error(
136-
"PermissionDenied",
136+
let msg = if is_standalone() {
137+
format!(
138+
"Requires {}, specify the required permissions during compilation using `deno compile --allow-{}`",
139+
Self::fmt_access(name, info),
140+
name
141+
)
142+
} else {
137143
format!(
138144
"Requires {}, run again with the --allow-{} flag",
139145
Self::fmt_access(name, info),
140146
name
141-
),
142-
)
147+
)
148+
};
149+
custom_error("PermissionDenied", msg)
143150
}
144151

145152
/// Check the permission state. bool is whether a prompt was issued.
@@ -2313,6 +2320,16 @@ pub fn create_child_permissions(
23132320
Ok(worker_perms)
23142321
}
23152322

2323+
static IS_STANDALONE: AtomicFlag = AtomicFlag::lowered();
2324+
2325+
pub fn mark_standalone() {
2326+
IS_STANDALONE.raise();
2327+
}
2328+
2329+
pub fn is_standalone() -> bool {
2330+
IS_STANDALONE.is_raised()
2331+
}
2332+
23162333
#[cfg(test)]
23172334
mod tests {
23182335
use super::*;

runtime/permissions/prompter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use std::io::StderrLock;
1111
use std::io::StdinLock;
1212
use std::io::Write as IoWrite;
1313

14+
use crate::is_standalone;
15+
1416
/// Helper function to make control characters visible so users can see the underlying filename.
1517
fn escape_control_characters(s: &str) -> std::borrow::Cow<str> {
1618
if !s.contains(|c: char| c.is_ascii_control() || c.is_control()) {
@@ -339,7 +341,11 @@ impl PermissionPrompter for TtyPrompter {
339341
))
340342
);
341343
writeln!(&mut output, "┠─ {}", colors::italic(&msg)).unwrap();
342-
let msg = format!("Run again with --allow-{name} to bypass this prompt.");
344+
let msg = if is_standalone() {
345+
format!("Specify the required permissions during compile time using `deno compile --allow-{name}`.")
346+
} else {
347+
format!("Run again with --allow-{name} to bypass this prompt.")
348+
};
343349
writeln!(&mut output, "┠─ {}", colors::italic(&msg)).unwrap();
344350
write!(&mut output, "┗ {}", colors::bold("Allow?")).unwrap();
345351
write!(&mut output, " {opts} > ").unwrap();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"tempDir": true,
3+
"steps": [{
4+
"if": "unix",
5+
"args": "compile --output main main.ts",
6+
"output": "[WILDCARD]"
7+
}, {
8+
"if": "unix",
9+
"commandName": "./main",
10+
"args": [],
11+
"exitCode": 1,
12+
"output": "main.out"
13+
}, {
14+
"if": "windows",
15+
"args": "compile --output main.exe main.ts",
16+
"output": "[WILDCARD]"
17+
}, {
18+
"if": "windows",
19+
"commandName": "./main.exe",
20+
"args": [],
21+
"exitCode": 1,
22+
"output": "main.out"
23+
}]
24+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: Uncaught (in promise) PermissionDenied: Requires run access to "deno", specify the required permissions during compilation using `deno compile --allow-run`
2+
[WILDCARD]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
new Deno.Command("deno").outputSync();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: Uncaught PermissionDenied: Requires read access to <CWD>, run again with the --allow-read flag
1+
error: Uncaught PermissionDenied: Requires read access to <CWD>, specify the required permissions during compilation using `deno compile --allow-read`
22
[WILDCARD]

0 commit comments

Comments
 (0)