summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs22
-rw-r--r--src/msg.fbs6
2 files changed, 28 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
diff --git a/src/msg.fbs b/src/msg.fbs
index 8b95ec741..ef2f4946b 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -20,6 +20,7 @@ union Any {
ReadFile,
ReadFileRes,
WriteFile,
+ CopyFile,
Rename,
Readlink,
ReadlinkRes,
@@ -214,6 +215,11 @@ table WriteFile {
// perm specified by https://godoc.org/os#FileMode
}
+table CopyFile {
+ from: string;
+ to: string;
+}
+
table Rename {
oldpath: string;
newpath: string;