summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs31
-rw-r--r--src/msg.fbs6
2 files changed, 36 insertions, 1 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index cf0d1a315..ad6552dc1 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -56,6 +56,7 @@ pub extern "C" fn msg_from_js(d: *const DenoC, buf: deno_buf) {
msg::Any::Remove => handle_remove,
msg::Any::ReadFile => handle_read_file,
msg::Any::Rename => handle_rename,
+ msg::Any::Symlink => handle_symlink,
msg::Any::SetEnv => handle_set_env,
msg::Any::Stat => handle_stat,
msg::Any::WriteFile => handle_write_file,
@@ -142,6 +143,13 @@ fn permission_denied() -> DenoError {
))
}
+fn not_implemented() -> DenoError {
+ DenoError::from(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ "Not implemented"
+ ))
+}
+
fn handle_exit(_d: *const DenoC, base: &msg::Base) -> Box<Op> {
let msg = base.msg_as_exit().unwrap();
std::process::exit(msg.code())
@@ -663,7 +671,7 @@ fn handle_rename(d: *const DenoC, base: &msg::Base) -> Box<Op> {
let isolate = from_c(d);
if !isolate.flags.allow_write {
return odd_future(permission_denied());
- };
+ }
let msg = base.msg_as_rename().unwrap();
let oldpath = String::from(msg.oldpath().unwrap());
let newpath = String::from(msg.newpath().unwrap());
@@ -673,3 +681,24 @@ fn handle_rename(d: *const DenoC, base: &msg::Base) -> Box<Op> {
Ok(None)
}()))
}
+
+fn handle_symlink(d: *const DenoC, base: &msg::Base) -> Box<Op> {
+ let deno = from_c(d);
+ if !deno.flags.allow_write {
+ return odd_future(permission_denied());
+ }
+ // TODO Use type for Windows.
+ if cfg!(windows) {
+ return odd_future(not_implemented());
+ } else {
+ let msg = base.msg_as_symlink().unwrap();
+ let oldname = String::from(msg.oldname().unwrap());
+ let newname = String::from(msg.newname().unwrap());
+ Box::new(futures::future::result(|| -> OpResult {
+ debug!("handle_symlink {} {}", oldname, newname);
+ #[cfg(any(unix))]
+ std::os::unix::fs::symlink(Path::new(&oldname), Path::new(&newname))?;
+ Ok(None)
+ }()))
+ }
+}
diff --git a/src/msg.fbs b/src/msg.fbs
index 37a48e2df..5a8d52f09 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -20,6 +20,7 @@ union Any {
ReadFileRes,
WriteFile,
Rename,
+ Symlink,
Stat,
StatRes,
SetEnv,
@@ -200,6 +201,11 @@ table Rename {
newpath: string;
}
+table Symlink {
+ oldname: string;
+ newname: string;
+}
+
table Stat {
filename: string;
lstat: bool;