summaryrefslogtreecommitdiff
path: root/cli/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/state.rs')
-rw-r--r--cli/state.rs41
1 files changed, 34 insertions, 7 deletions
diff --git a/cli/state.rs b/cli/state.rs
index ca64e6d6c..1f44f254f 100644
--- a/cli/state.rs
+++ b/cli/state.rs
@@ -9,6 +9,7 @@ use crate::file_fetcher::SourceFileFetcher;
use crate::flags;
use crate::global_timer::GlobalTimer;
use crate::import_map::ImportMap;
+use crate::lockfile::Lockfile;
use crate::msg;
use crate::ops::JsonOp;
use crate::permissions::DenoPermissions;
@@ -88,6 +89,8 @@ pub struct State {
pub ts_compiler: TsCompiler,
pub include_deno_namespace: bool,
+
+ pub lockfile: Option<Mutex<Lockfile>>,
}
impl Clone for ThreadSafeState {
@@ -255,6 +258,13 @@ impl ThreadSafeState {
let modules = Arc::new(Mutex::new(deno::Modules::new()));
+ // Note: reads lazily from disk on first call to lockfile.check()
+ let lockfile = if let Some(filename) = &flags.lock {
+ Some(Mutex::new(Lockfile::new(filename.to_string())))
+ } else {
+ None
+ };
+
let state = State {
main_module,
modules,
@@ -276,6 +286,7 @@ impl ThreadSafeState {
js_compiler: JsCompiler {},
json_compiler: JsonCompiler {},
include_deno_namespace,
+ lockfile,
};
Ok(ThreadSafeState(Arc::new(state)))
@@ -285,30 +296,46 @@ impl ThreadSafeState {
self: &Self,
module_specifier: &ModuleSpecifier,
) -> impl Future<Item = CompiledModule, Error = ErrBox> {
- let state_ = self.clone();
+ let state1 = self.clone();
+ let state2 = self.clone();
self
.file_fetcher
.fetch_source_file_async(&module_specifier)
.and_then(move |out| match out.media_type {
msg::MediaType::Unknown => {
- state_.js_compiler.compile_async(state_.clone(), &out)
+ state1.js_compiler.compile_async(state1.clone(), &out)
}
msg::MediaType::Json => {
- state_.json_compiler.compile_async(state_.clone(), &out)
+ state1.json_compiler.compile_async(state1.clone(), &out)
}
msg::MediaType::TypeScript
| msg::MediaType::TSX
| msg::MediaType::JSX => {
- state_.ts_compiler.compile_async(state_.clone(), &out)
+ state1.ts_compiler.compile_async(state1.clone(), &out)
}
msg::MediaType::JavaScript => {
- if state_.ts_compiler.compile_js {
- state_.ts_compiler.compile_async(state_.clone(), &out)
+ if state1.ts_compiler.compile_js {
+ state1.ts_compiler.compile_async(state1.clone(), &out)
} else {
- state_.js_compiler.compile_async(state_.clone(), &out)
+ state1.js_compiler.compile_async(state1.clone(), &out)
+ }
+ }
+ })
+ .and_then(move |compiled_module| {
+ if let Some(ref lockfile) = state2.lockfile {
+ let mut g = lockfile.lock().unwrap();
+ if state2.flags.lock_write {
+ g.insert(&compiled_module);
+ } else if !g.check(&compiled_module)? {
+ eprintln!(
+ "Subresource integrety check failed --lock={}\n{}",
+ g.filename, compiled_module.name
+ );
+ std::process::exit(10);
}
}
+ Ok(compiled_module)
})
}