summaryrefslogtreecommitdiff
path: root/cli/ops
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops')
-rw-r--r--cli/ops/files.rs11
-rw-r--r--cli/ops/fs.rs95
-rw-r--r--cli/ops/permissions.rs20
-rw-r--r--cli/ops/plugins.rs5
-rw-r--r--cli/ops/tls.rs7
5 files changed, 67 insertions, 71 deletions
diff --git a/cli/ops/files.rs b/cli/ops/files.rs
index 5a8694019..8bb3c8acb 100644
--- a/cli/ops/files.rs
+++ b/cli/ops/files.rs
@@ -12,6 +12,7 @@ use futures::future::FutureExt;
use std;
use std::convert::From;
use std::io::SeekFrom;
+use std::path::Path;
use tokio;
pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
@@ -34,7 +35,7 @@ fn op_open(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: OpenArgs = serde_json::from_value(args)?;
- let (filename, filename_) = deno_fs::resolve_from_cwd(&args.filename)?;
+ let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
let mode = args.mode.as_ref();
let state_ = state.clone();
let mut open_options = tokio::fs::OpenOptions::new();
@@ -75,14 +76,14 @@ fn op_open(
match mode {
"r" => {
- state.check_read(&filename_)?;
+ state.check_read(&filename)?;
}
"w" | "a" | "x" => {
- state.check_write(&filename_)?;
+ state.check_write(&filename)?;
}
&_ => {
- state.check_read(&filename_)?;
- state.check_write(&filename_)?;
+ state.check_read(&filename)?;
+ state.check_write(&filename)?;
}
}
diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs
index c6830ddd2..80972aef1 100644
--- a/cli/ops/fs.rs
+++ b/cli/ops/fs.rs
@@ -10,7 +10,7 @@ use deno_core::*;
use remove_dir_all::remove_dir_all;
use std::convert::From;
use std::fs;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
#[cfg(unix)]
@@ -71,13 +71,13 @@ fn op_mkdir(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: MkdirArgs = serde_json::from_value(args)?;
- let (path, path_) = deno_fs::resolve_from_cwd(args.path.as_ref())?;
+ let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
- state.check_write(&path_)?;
+ state.check_write(&path)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
- debug!("op_mkdir {}", path_);
+ debug!("op_mkdir {}", path.display());
deno_fs::mkdir(&path, args.mode, args.recursive)?;
Ok(json!({}))
})
@@ -98,13 +98,13 @@ fn op_chmod(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: ChmodArgs = serde_json::from_value(args)?;
- let (path, path_) = deno_fs::resolve_from_cwd(args.path.as_ref())?;
+ let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
- state.check_write(&path_)?;
+ state.check_write(&path)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
- debug!("op_chmod {}", &path_);
+ debug!("op_chmod {}", path.display());
// Still check file/dir exists on windows
let _metadata = fs::metadata(&path)?;
#[cfg(any(unix))]
@@ -132,12 +132,13 @@ fn op_chown(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: ChownArgs = serde_json::from_value(args)?;
+ let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
- state.check_write(&args.path)?;
+ state.check_write(&path)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
- debug!("op_chown {}", &args.path);
+ debug!("op_chown {}", path.display());
match deno_fs::chown(args.path.as_ref(), args.uid, args.gid) {
Ok(_) => Ok(json!({})),
Err(e) => Err(e),
@@ -159,10 +160,10 @@ fn op_remove(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: RemoveArgs = serde_json::from_value(args)?;
- let (path, path_) = deno_fs::resolve_from_cwd(args.path.as_ref())?;
+ let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
let recursive = args.recursive;
- state.check_write(&path_)?;
+ state.check_write(&path)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
@@ -193,12 +194,11 @@ fn op_copy_file(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: CopyFileArgs = serde_json::from_value(args)?;
+ let from = deno_fs::resolve_from_cwd(Path::new(&args.from))?;
+ let to = deno_fs::resolve_from_cwd(Path::new(&args.to))?;
- let (from, from_) = deno_fs::resolve_from_cwd(args.from.as_ref())?;
- let (to, to_) = deno_fs::resolve_from_cwd(args.to.as_ref())?;
-
- state.check_read(&from_)?;
- state.check_write(&to_)?;
+ state.check_read(&from)?;
+ state.check_write(&to)?;
debug!("op_copy_file {} {}", from.display(), to.display());
let is_sync = args.promise_id.is_none();
@@ -293,12 +293,10 @@ fn op_stat(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: StatArgs = serde_json::from_value(args)?;
-
- let (filename, filename_) =
- deno_fs::resolve_from_cwd(args.filename.as_ref())?;
+ let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
let lstat = args.lstat;
- state.check_read(&filename_)?;
+ state.check_read(&filename)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
@@ -325,12 +323,13 @@ fn op_realpath(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: RealpathArgs = serde_json::from_value(args)?;
- let (_, path_) = deno_fs::resolve_from_cwd(args.path.as_ref())?;
- state.check_read(&path_)?;
- let path = args.path.clone();
+ let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
+
+ state.check_read(&path)?;
+
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
- debug!("op_realpath {}", &path);
+ debug!("op_realpath {}", path.display());
// corresponds to the realpath on Unix and
// CreateFile and GetFinalPathNameByHandle on Windows
let realpath = fs::canonicalize(&path)?;
@@ -356,14 +355,13 @@ fn op_read_dir(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: ReadDirArgs = serde_json::from_value(args)?;
- let (path, path_) = deno_fs::resolve_from_cwd(args.path.as_ref())?;
+ let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
- state.check_read(&path_)?;
+ state.check_read(&path)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
debug!("op_read_dir {}", path.display());
-
let entries: Vec<_> = fs::read_dir(path)?
.map(|entry| {
let entry = entry.unwrap();
@@ -394,13 +392,12 @@ fn op_rename(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: RenameArgs = serde_json::from_value(args)?;
+ let oldpath = deno_fs::resolve_from_cwd(Path::new(&args.oldpath))?;
+ let newpath = deno_fs::resolve_from_cwd(Path::new(&args.newpath))?;
- let (oldpath, oldpath_) = deno_fs::resolve_from_cwd(args.oldpath.as_ref())?;
- let (newpath, newpath_) = deno_fs::resolve_from_cwd(args.newpath.as_ref())?;
-
- state.check_read(&oldpath_)?;
- state.check_write(&oldpath_)?;
- state.check_write(&newpath_)?;
+ state.check_read(&oldpath)?;
+ state.check_write(&oldpath)?;
+ state.check_write(&newpath)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
@@ -424,12 +421,11 @@ fn op_link(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: LinkArgs = serde_json::from_value(args)?;
+ let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?;
+ let newname = deno_fs::resolve_from_cwd(Path::new(&args.newname))?;
- let (oldname, oldname_) = deno_fs::resolve_from_cwd(args.oldname.as_ref())?;
- let (newname, newname_) = deno_fs::resolve_from_cwd(args.newname.as_ref())?;
-
- state.check_read(&oldname_)?;
- state.check_write(&newname_)?;
+ state.check_read(&oldname)?;
+ state.check_write(&newname)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
@@ -453,11 +449,10 @@ fn op_symlink(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: SymlinkArgs = serde_json::from_value(args)?;
+ let oldname = deno_fs::resolve_from_cwd(Path::new(&args.oldname))?;
+ let newname = deno_fs::resolve_from_cwd(Path::new(&args.newname))?;
- let (oldname, _oldname_) = deno_fs::resolve_from_cwd(args.oldname.as_ref())?;
- let (newname, newname_) = deno_fs::resolve_from_cwd(args.newname.as_ref())?;
-
- state.check_write(&newname_)?;
+ state.check_write(&newname)?;
// TODO Use type for Windows.
if cfg!(windows) {
return Err(
@@ -486,10 +481,9 @@ fn op_read_link(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: ReadLinkArgs = serde_json::from_value(args)?;
+ let name = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
- let (name, name_) = deno_fs::resolve_from_cwd(args.name.as_ref())?;
-
- state.check_read(&name_)?;
+ state.check_read(&name)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
@@ -515,15 +509,14 @@ fn op_truncate(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: TruncateArgs = serde_json::from_value(args)?;
-
- let (filename, filename_) = deno_fs::resolve_from_cwd(args.name.as_ref())?;
+ let filename = deno_fs::resolve_from_cwd(Path::new(&args.name))?;
let len = args.len;
- state.check_write(&filename_)?;
+ state.check_write(&filename)?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
- debug!("op_truncate {} {}", filename_, len);
+ debug!("op_truncate {} {}", filename.display(), len);
let f = fs::OpenOptions::new().write(true).open(&filename)?;
f.set_len(len)?;
Ok(json!({}))
@@ -547,7 +540,7 @@ fn op_make_temp_dir(
let args: MakeTempDirArgs = serde_json::from_value(args)?;
// FIXME
- state.check_write("make_temp")?;
+ state.check_write(Path::new("make_temp"))?;
let dir = args.dir.map(PathBuf::from);
let prefix = args.prefix.map(String::from);
@@ -585,7 +578,7 @@ fn op_utime(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: Utime = serde_json::from_value(args)?;
- state.check_write(&args.filename)?;
+ state.check_write(Path::new(&args.filename))?;
let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
debug!("op_utimes {} {} {}", args.filename, args.atime, args.mtime);
diff --git a/cli/ops/permissions.rs b/cli/ops/permissions.rs
index 6a0186acc..172ce97b1 100644
--- a/cli/ops/permissions.rs
+++ b/cli/ops/permissions.rs
@@ -5,6 +5,7 @@ use crate::fs as deno_fs;
use crate::ops::json_op;
use crate::state::ThreadSafeState;
use deno_core::*;
+use std::path::Path;
pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op(
@@ -29,9 +30,8 @@ struct PermissionArgs {
}
fn resolve_path(path: &str) -> String {
- deno_fs::resolve_from_cwd(path)
+ deno_fs::resolve_from_cwd(Path::new(path))
.unwrap()
- .0
.to_str()
.unwrap()
.to_string()
@@ -48,7 +48,7 @@ pub fn op_query_permission(
let perm = permissions.get_permission_state(
&args.name,
&args.url.as_ref().map(String::as_str),
- &resolved_path.as_ref().map(String::as_str),
+ &resolved_path.as_ref().map(String::as_str).map(Path::new),
)?;
Ok(JsonOp::Sync(json!({ "state": perm.to_string() })))
}
@@ -74,7 +74,7 @@ pub fn op_revoke_permission(
let perm = permissions.get_permission_state(
&args.name,
&args.url.as_ref().map(String::as_str),
- &resolved_path.as_ref().map(String::as_str),
+ &resolved_path.as_ref().map(String::as_str).map(Path::new),
)?;
Ok(JsonOp::Sync(json!({ "state": perm.to_string() })))
}
@@ -89,12 +89,12 @@ pub fn op_request_permission(
let resolved_path = args.path.as_ref().map(String::as_str).map(resolve_path);
let perm = match args.name.as_ref() {
"run" => Ok(permissions.request_run()),
- "read" => {
- Ok(permissions.request_read(&resolved_path.as_ref().map(String::as_str)))
- }
- "write" => {
- Ok(permissions.request_write(&resolved_path.as_ref().map(String::as_str)))
- }
+ "read" => Ok(permissions.request_read(
+ &resolved_path.as_ref().map(String::as_str).map(Path::new),
+ )),
+ "write" => Ok(permissions.request_write(
+ &resolved_path.as_ref().map(String::as_str).map(Path::new),
+ )),
"net" => permissions.request_net(&args.url.as_ref().map(String::as_str)),
"env" => Ok(permissions.request_env()),
"plugin" => Ok(permissions.request_plugin()),
diff --git a/cli/ops/plugins.rs b/cli/ops/plugins.rs
index 747ea859d..e31040a41 100644
--- a/cli/ops/plugins.rs
+++ b/cli/ops/plugins.rs
@@ -6,6 +6,7 @@ use deno_core::*;
use dlopen::symbor::Library;
use std::collections::HashMap;
use std::ffi::OsStr;
+use std::path::Path;
use std::sync::Arc;
pub fn init(
@@ -62,9 +63,9 @@ pub fn op_open_plugin(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: OpenPluginArgs = serde_json::from_value(args)?;
- let (filename, filename_) = deno_fs::resolve_from_cwd(&args.filename)?;
+ let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;
- state.check_plugin(&filename_)?;
+ state.check_plugin(&filename)?;
let lib = open_plugin(filename)?;
let plugin_resource = PluginResource {
diff --git a/cli/ops/tls.rs b/cli/ops/tls.rs
index cb0ae2ecb..87a067a9e 100644
--- a/cli/ops/tls.rs
+++ b/cli/ops/tls.rs
@@ -16,6 +16,7 @@ use std::fs::File;
use std::future::Future;
use std::io::BufReader;
use std::net::SocketAddr;
+use std::path::Path;
use std::pin::Pin;
use std::sync::Arc;
use std::task::Context;
@@ -69,7 +70,7 @@ pub fn op_connect_tls(
let state_ = state.clone();
state.check_net(&args.hostname, args.port)?;
if let Some(path) = cert_file.clone() {
- state.check_read(&path)?;
+ state.check_read(Path::new(&path))?;
}
let mut domain = args.hostname.clone();
@@ -254,8 +255,8 @@ fn op_listen_tls(
let key_file = args.key_file;
state.check_net(&args.hostname, args.port)?;
- state.check_read(&cert_file)?;
- state.check_read(&key_file)?;
+ state.check_read(Path::new(&cert_file))?;
+ state.check_read(Path::new(&key_file))?;
let mut config = ServerConfig::new(NoClientAuth::new());
config