diff options
Diffstat (limited to 'src/handlers.rs')
-rw-r--r-- | src/handlers.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index b1ef67d94..c615f5669 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -77,6 +77,7 @@ pub fn msg_from_js( msg::Any::Symlink => handle_symlink, msg::Any::SetEnv => handle_set_env, msg::Any::Stat => handle_stat, + msg::Any::Truncate => handle_truncate, msg::Any::WriteFile => handle_write_file, msg::Any::Exit => handle_exit, _ => panic!(format!( @@ -977,3 +978,25 @@ fn handle_read_link( )) }) } + +fn handle_truncate( + state: Arc<IsolateState>, + base: &msg::Base, + data: &'static mut [u8], +) -> Box<Op> { + assert_eq!(data.len(), 0); + + if !state.flags.allow_write { + return odd_future(permission_denied()); + } + + let msg = base.msg_as_truncate().unwrap(); + let filename = String::from(msg.name().unwrap()); + let len = msg.len(); + blocking!(base.sync(), || { + debug!("handle_truncate {} {}", filename, len); + let f = fs::OpenOptions::new().write(true).open(&filename)?; + f.set_len(len as u64)?; + Ok(empty_buf()) + }) +} |