summaryrefslogtreecommitdiff
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-09-30 15:06:41 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-30 18:06:41 -0400
commit50a9c2b575b383e72f64e16e83e540c215482e73 (patch)
treeb6ace8c3b76549b39c691029ad318accf09a6c90 /src/handlers.rs
parenteceeabdab29a8efab95990f2847fc21da39dfd66 (diff)
Add copyFile/copyFileSync (#863)
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index c615f5669..1f861f000 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -80,6 +80,7 @@ pub fn msg_from_js(
msg::Any::Truncate => handle_truncate,
msg::Any::WriteFile => handle_write_file,
msg::Any::Exit => handle_exit,
+ msg::Any::CopyFile => handle_copy_file,
_ => panic!(format!(
"Unhandled message {}",
msg::enum_name_any(msg_type)
@@ -747,6 +748,27 @@ fn handle_read_file(
})
}
+fn handle_copy_file(
+ state: Arc<IsolateState>,
+ base: &msg::Base,
+ data: &'static mut [u8],
+) -> Box<Op> {
+ assert_eq!(data.len(), 0);
+ let msg = base.msg_as_copy_file().unwrap();
+ let from = PathBuf::from(msg.from().unwrap());
+ let to = PathBuf::from(msg.to().unwrap());
+
+ if !state.flags.allow_write {
+ return odd_future(permission_denied());
+ }
+
+ debug!("handle_copy_file {} {}", from.display(), to.display());
+ blocking!(base.sync(), || {
+ fs::copy(&from, &to)?;
+ Ok(empty_buf())
+ })
+}
+
macro_rules! to_seconds {
($time:expr) => {{
// Unwrap is safe here as if the file is before the unix epoch