diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/BUILD.gn | 2 | ||||
-rw-r--r-- | cli/Cargo.toml | 1 | ||||
-rw-r--r-- | cli/msg.fbs | 7 | ||||
-rw-r--r-- | cli/ops.rs | 25 |
4 files changed, 35 insertions, 0 deletions
diff --git a/cli/BUILD.gn b/cli/BUILD.gn index dc11f3b0b..bfa3fe427 100644 --- a/cli/BUILD.gn +++ b/cli/BUILD.gn @@ -38,6 +38,7 @@ main_extern = [ "$rust_build:tokio_rustls", "$rust_build:tokio_threadpool", "$rust_build:url", + "$rust_build:utime", ] if (is_win) { main_extern += [ "$rust_build:winapi" ] @@ -105,6 +106,7 @@ ts_sources = [ "../js/url.ts", "../js/url_search_params.ts", "../js/util.ts", + "../js/utime.ts", "../js/window.ts", "../js/workers.ts", "../js/write_file.ts", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ff35a330a..8ad8735de 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -47,6 +47,7 @@ tokio-process = "0.2.3" tokio-rustls = "0.9.2" tokio-threadpool = "0.1.14" url = "1.7.2" +utime = "0.2.1" [target.'cfg(windows)'.dependencies] winapi = "0.3.7" diff --git a/cli/msg.fbs b/cli/msg.fbs index ff5454a91..b93fb68a7 100644 --- a/cli/msg.fbs +++ b/cli/msg.fbs @@ -67,6 +67,7 @@ union Any { StatRes, Symlink, Truncate, + Utime, CreateWorker, CreateWorkerRes, HostGetWorkerClosed, @@ -434,6 +435,12 @@ table Truncate { len: uint; } +table Utime { + filename: string; + atime: uint64; + mtime: uint64; +} + table Open { filename: string; perm: uint; diff --git a/cli/ops.rs b/cli/ops.rs index 4ebcf5fdb..d8a0c5cfa 100644 --- a/cli/ops.rs +++ b/cli/ops.rs @@ -50,6 +50,7 @@ use tokio::net::TcpListener; use tokio::net::TcpStream; use tokio_process::CommandExt; use tokio_threadpool; +use utime; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; @@ -202,6 +203,7 @@ pub fn op_selector_std(inner_type: msg::Any) -> Option<OpCreator> { msg::Any::Stat => Some(op_stat), msg::Any::Symlink => Some(op_symlink), msg::Any::Truncate => Some(op_truncate), + msg::Any::Utime => Some(op_utime), msg::Any::CreateWorker => Some(op_create_worker), msg::Any::HostGetWorkerClosed => Some(op_host_get_worker_closed), msg::Any::HostGetMessage => Some(op_host_get_message), @@ -1507,6 +1509,29 @@ fn op_truncate( }) } +fn op_utime( + state: &ThreadSafeState, + base: &msg::Base<'_>, + data: deno_buf, +) -> Box<OpWithError> { + assert_eq!(data.len(), 0); + + let inner = base.inner_as_utime().unwrap(); + let filename = String::from(inner.filename().unwrap()); + let atime = inner.atime(); + let mtime = inner.mtime(); + + if let Err(e) = state.check_write(&filename) { + return odd_future(e); + } + + blocking(base.sync(), move || { + debug!("op_utimes {} {} {}", filename, atime, mtime); + utime::set_file_times(filename, atime, mtime)?; + Ok(empty_buf()) + }) +} + fn op_listen( state: &ThreadSafeState, base: &msg::Base<'_>, |