Skip to content

Commit

Permalink
move fs ops to standalone crate
Browse files Browse the repository at this point in the history
Still a couple of things to figure out here

1. I would like to standardize providing permissions access to standalone ops.
2. We need a way to pass error kind that is outwardly extensible. Maybe just strings, since we are using json?
  • Loading branch information
afinch7 committed Sep 3, 2019
1 parent 3e4c3f4 commit da3e91c
Show file tree
Hide file tree
Showing 17 changed files with 608 additions and 71 deletions.
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ members = [
"tools/hyper_hello",
"deno_typescript",
"cli_snapshots",
"ops/dispatch_json",
"ops/fs",
]
2 changes: 2 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ edition = "2018"

[dependencies]
deno = { path = "../core" }
deno_dispatch_json = { path = "../ops/dispatch_json" }
deno_ops_fs = { path = "../ops/fs" }

ansi_term = "0.12.0"
atty = "0.2.13"
Expand Down
2 changes: 1 addition & 1 deletion cli/compilers/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ impl TsCompiler {
#[cfg(test)]
mod tests {
use super::*;
use crate::fs as deno_fs;
use crate::tokio_util;
use deno::ModuleSpecifier;
use deno_ops_fs::fs as deno_fs;
use std::path::PathBuf;
use tempfile::TempDir;

Expand Down
2 changes: 1 addition & 1 deletion cli/disk_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::fs as deno_fs;
use deno_ops_fs::fs as deno_fs;
use std::ffi::OsStr;
use std::fs;
use std::path::Component;
Expand Down
2 changes: 1 addition & 1 deletion cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl SourceCodeHeaders {
#[cfg(test)]
mod tests {
use super::*;
use crate::fs as deno_fs;
use deno_ops_fs::fs as deno_fs;
use tempfile::TempDir;

impl SourceFileFetcher {
Expand Down
2 changes: 1 addition & 1 deletion cli/flags.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::fs as deno_fs;
use clap::App;
use clap::AppSettings;
use clap::Arg;
use clap::ArgMatches;
use clap::Shell;
use clap::SubCommand;
use deno::ModuleSpecifier;
use deno_ops_fs::fs as deno_fs;
use log::Level;
use std;
use std::str;
Expand Down
2 changes: 1 addition & 1 deletion cli/ops/files.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{wrap_json_op, Deserialize, JsonOp};
use crate::deno_error;
use crate::fs as deno_fs;
use crate::resources;
use crate::state::DenoOpDispatcher;
use crate::state::ThreadSafeState;
use deno::*;
use deno_ops_fs::fs as deno_fs;
use futures::Future;
use std;
use std::convert::From;
Expand Down
42 changes: 25 additions & 17 deletions cli/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::state::ThreadSafeState;
use deno::*;
use deno_ops_fs as fs;
use std::sync::Arc;

mod compiler;
// TODO(afinch7) remove this.
mod dispatch_json;
mod dispatch_minimal;
mod errors;
mod fetch;
mod files;
mod fs;
mod io;
mod metrics;
mod net;
Expand Down Expand Up @@ -46,23 +47,30 @@ pub fn setup_dispatcher_registry(state: ThreadSafeState) -> Arc<OpDisReg> {
registry.register_op(OP_NAMESPACE, state.wrap_op(files::OpClose));
registry.register_op(OP_NAMESPACE, state.wrap_op(files::OpSeek));

let state_ = state.clone();
let state__ = state.clone();
let fs_state = fs::TSFsOpsState::new(
move |filename| state_.check_read(filename),
move |filename| state__.check_write(filename),
);

// Fs
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpChdir));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpMkdir));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpChmod));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpChown));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpRemove));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpCopyFile));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpStat));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpReadDir));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpRename));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpLink));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpSymlink));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpReadLink));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpTruncate));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpMakeTempDir));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpUtime));
registry.register_op(OP_NAMESPACE, state.wrap_op(fs::OpCwd));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpChdir));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpMkdir));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpChmod));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpChown));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpRemove));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpCopyFile));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpStat));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpReadDir));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpRename));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpLink));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpSymlink));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpReadLink));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpTruncate));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpMakeTempDir));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpUtime));
registry.register_op(OP_NAMESPACE, fs_state.wrap_op(fs::OpCwd));

// Io
registry.register_op(OP_NAMESPACE, state.wrap_op(io::OpRead));
Expand Down
2 changes: 1 addition & 1 deletion cli/ops/os.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{wrap_json_op, Deserialize, JsonOp};
use crate::ansi;
use crate::fs as deno_fs;
use crate::state::DenoOpDispatcher;
use crate::state::ThreadSafeState;
use crate::version;
use atty;
use deno::*;
use deno_ops_fs::fs as deno_fs;
use log;
use std::collections::HashMap;
use std::env;
Expand Down
22 changes: 22 additions & 0 deletions ops/dispatch_json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "deno_dispatch_json"
version = "0.16.0"
edition = "2018"
authors = ["The deno authors <[email protected]>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/denoland/deno"

[lib]
path = "lib.rs"

[dependencies]
deno = { path = "../../core" }

log = "0.4.8"
futures = "0.1.28"
serde = { version = "1.0.99", features = ["derive"] }
serde_derive = "1.0.99"
serde_json = { version = "1.0.40", features = [ "preserve_order" ] }
tokio-executor = "0.1.8"
tokio-threadpool = "0.1.15"
Loading

0 comments on commit da3e91c

Please sign in to comment.