diff options
Diffstat (limited to 'src/permissions.rs')
-rw-r--r-- | src/permissions.rs | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/permissions.rs b/src/permissions.rs index 7ca13d44a..d86992da3 100644 --- a/src/permissions.rs +++ b/src/permissions.rs @@ -5,40 +5,41 @@ use flags::DenoFlags; use errors::permission_denied; use errors::DenoResult; use std::io; +use std::sync::atomic::{AtomicBool, Ordering}; #[cfg_attr(feature = "cargo-clippy", allow(stutter))] -#[derive(Debug, Default, PartialEq)] +#[derive(Debug, Default)] pub struct DenoPermissions { - pub allow_write: bool, - pub allow_net: bool, - pub allow_env: bool, - pub allow_run: bool, + pub allow_write: AtomicBool, + pub allow_net: AtomicBool, + pub allow_env: AtomicBool, + pub allow_run: AtomicBool, } impl DenoPermissions { pub fn new(flags: &DenoFlags) -> Self { Self { - allow_write: flags.allow_write, - allow_env: flags.allow_env, - allow_net: flags.allow_net, - allow_run: flags.allow_run, + allow_write: AtomicBool::new(flags.allow_write), + allow_env: AtomicBool::new(flags.allow_env), + allow_net: AtomicBool::new(flags.allow_net), + allow_run: AtomicBool::new(flags.allow_run), } } - pub fn check_run(&mut self) -> DenoResult<()> { - if self.allow_run { + pub fn check_run(&self) -> DenoResult<()> { + if self.allow_run.load(Ordering::SeqCst) { return Ok(()); }; // TODO get location (where access occurred) let r = permission_prompt("Deno requests access to run a subprocess."); if r.is_ok() { - self.allow_run = true; + self.allow_run.store(true, Ordering::SeqCst); } r } - pub fn check_write(&mut self, filename: &str) -> DenoResult<()> { - if self.allow_write { + pub fn check_write(&self, filename: &str) -> DenoResult<()> { + if self.allow_write.load(Ordering::SeqCst) { return Ok(()); }; // TODO get location (where access occurred) @@ -47,13 +48,13 @@ impl DenoPermissions { filename ));; if r.is_ok() { - self.allow_write = true; + self.allow_write.store(true, Ordering::SeqCst); } r } - pub fn check_net(&mut self, domain_name: &str) -> DenoResult<()> { - if self.allow_net { + pub fn check_net(&self, domain_name: &str) -> DenoResult<()> { + if self.allow_net.load(Ordering::SeqCst) { return Ok(()); }; // TODO get location (where access occurred) @@ -62,20 +63,20 @@ impl DenoPermissions { domain_name )); if r.is_ok() { - self.allow_net = true; + self.allow_net.store(true, Ordering::SeqCst); } r } - pub fn check_env(&mut self) -> DenoResult<()> { - if self.allow_env { + pub fn check_env(&self) -> DenoResult<()> { + if self.allow_env.load(Ordering::SeqCst) { return Ok(()); }; // TODO get location (where access occurred) let r = permission_prompt(&"Deno requests access to environment variables."); if r.is_ok() { - self.allow_env = true; + self.allow_env.store(true, Ordering::SeqCst); } r } |