From 7e4ca7315efca97c7176ed1bcb51b54875378f90 Mon Sep 17 00:00:00 2001 From: Arshia Ghafoori Date: Wed, 2 Aug 2023 19:42:14 +0400 Subject: [PATCH] Fix path_rename syscall failing --- lib/wasix/src/syscalls/wasi/path_rename.rs | 36 +++++++--------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/lib/wasix/src/syscalls/wasi/path_rename.rs b/lib/wasix/src/syscalls/wasi/path_rename.rs index 810d0aa4eff..e25e3bbd20f 100644 --- a/lib/wasix/src/syscalls/wasi/path_rename.rs +++ b/lib/wasix/src/syscalls/wasi/path_rename.rs @@ -115,23 +115,8 @@ pub fn path_rename( { let mut guard = source_entry.write(); match guard.deref_mut() { - Kind::File { - handle, ref path, .. - } => { - // TODO: investigate why handle is not always there, it probably should be. - // My best guess is the fact that a handle means currently open and a path - // just means reference to host file on disk. But ideally those concepts - // could just be unified even if there's a `Box` which just - // implements the logic of "I'm not actually a file, I'll try to be as needed". - let result = if let Some(h) = handle { - drop(guard); - let state = state; - __asyncify_light(env, None, async move { - state - .fs_rename(source_path, &host_adjusted_target_path) - .await - })? - } else { + Kind::File { ref path, .. } => { + let result = { let path_clone = path.clone(); drop(guard); let out = { @@ -143,14 +128,6 @@ pub fn path_rename( .await })? }; - { - let mut guard = source_entry.write(); - if let Kind::File { ref mut path, .. } = guard.deref_mut() { - *path = host_adjusted_target_path; - } else { - unreachable!() - } - } out }; // if the above operation failed we have to revert the previous change and then fail @@ -160,6 +137,15 @@ pub fn path_rename( entries.insert(source_entry_name, source_entry); return Ok(e); } + } else { + { + let mut guard = source_entry.write(); + if let Kind::File { ref mut path, .. } = guard.deref_mut() { + *path = host_adjusted_target_path; + } else { + unreachable!() + } + } } } Kind::Dir { ref path, .. } => {