summaryrefslogtreecommitdiff
path: root/cli/state.rs
diff options
context:
space:
mode:
authorNayeem Rahman <muhammed.9939@gmail.com>2020-01-20 14:45:44 +0000
committerRy Dahl <ry@tinyclouds.org>2020-01-20 09:45:44 -0500
commit7f80f9db3f4c3b064b230adfec7ff958fc195da6 (patch)
treebda74057420a1b51ce293918b6e67123715ee945 /cli/state.rs
parent60b53fd6b6dc2af83a64c332b9f3a1926f43d631 (diff)
refactor: Improve path handling in permission checks (#3714)
Diffstat (limited to 'cli/state.rs')
-rw-r--r--cli/state.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/cli/state.rs b/cli/state.rs
index ed7b8e438..acd661f25 100644
--- a/cli/state.rs
+++ b/cli/state.rs
@@ -26,6 +26,7 @@ use serde_json::Value;
use std;
use std::collections::HashMap;
use std::ops::Deref;
+use std::path::Path;
use std::pin::Pin;
use std::str;
use std::sync::atomic::AtomicUsize;
@@ -268,13 +269,13 @@ impl ThreadSafeState {
}
#[inline]
- pub fn check_read(&self, filename: &str) -> Result<(), ErrBox> {
- self.permissions.lock().unwrap().check_read(filename)
+ pub fn check_read(&self, path: &Path) -> Result<(), ErrBox> {
+ self.permissions.lock().unwrap().check_read(path)
}
#[inline]
- pub fn check_write(&self, filename: &str) -> Result<(), ErrBox> {
- self.permissions.lock().unwrap().check_write(filename)
+ pub fn check_write(&self, path: &Path) -> Result<(), ErrBox> {
+ self.permissions.lock().unwrap().check_write(path)
}
#[inline]
@@ -298,7 +299,7 @@ impl ThreadSafeState {
}
#[inline]
- pub fn check_plugin(&self, filename: &str) -> Result<(), ErrBox> {
+ pub fn check_plugin(&self, filename: &Path) -> Result<(), ErrBox> {
self.permissions.lock().unwrap().check_plugin(filename)
}
@@ -313,13 +314,13 @@ impl ThreadSafeState {
Ok(())
}
"file" => {
- let filename = u
+ let path = u
.to_file_path()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
- self.check_read(&filename)?;
+ self.check_read(Path::new(&path))?;
Ok(())
}
_ => Err(permission_denied()),