diff --git a/lib/wasix/src/syscalls/wasi/path_rename.rs b/lib/wasix/src/syscalls/wasi/path_rename.rs index 810d0aa4eff..50e86a90bf5 100644 --- a/lib/wasix/src/syscalls/wasi/path_rename.rs +++ b/lib/wasix/src/syscalls/wasi/path_rename.rs @@ -115,34 +115,26 @@ 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 { + Kind::File { ref path, .. } => { + let result = { + let path_clone = path.clone(); drop(guard); let state = state; + let host_adjusted_target_path = host_adjusted_target_path.clone(); __asyncify_light(env, None, async move { state - .fs_rename(source_path, &host_adjusted_target_path) + .fs_rename(path_clone, &host_adjusted_target_path) .await })? + }; + // if the above operation failed we have to revert the previous change and then fail + if let Err(e) = result { + let mut guard = source_parent_inode.write(); + if let Kind::Dir { entries, .. } = guard.deref_mut() { + entries.insert(source_entry_name, source_entry); + return Ok(e); + } } else { - let path_clone = path.clone(); - drop(guard); - let out = { - let state = state; - let host_adjusted_target_path = host_adjusted_target_path.clone(); - __asyncify_light(env, None, async move { - state - .fs_rename(path_clone, &host_adjusted_target_path) - .await - })? - }; { let mut guard = source_entry.write(); if let Kind::File { ref mut path, .. } = guard.deref_mut() { @@ -151,15 +143,6 @@ pub fn path_rename( unreachable!() } } - out - }; - // if the above operation failed we have to revert the previous change and then fail - if let Err(e) = result { - let mut guard = source_parent_inode.write(); - if let Kind::Dir { entries, .. } = guard.deref_mut() { - entries.insert(source_entry_name, source_entry); - return Ok(e); - } } } Kind::Dir { ref path, .. } => {