Skip to content

Commit

Permalink
Fix path_rename syscall failing
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshia001 committed Aug 2, 2023
1 parent c424fff commit 7e4ca73
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions lib/wasix/src/syscalls/wasi/path_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,8 @@ pub fn path_rename<M: MemorySize>(
{
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<dyn VirtualFile>` 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 = {
Expand All @@ -143,14 +128,6 @@ pub fn path_rename<M: MemorySize>(
.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
Expand All @@ -160,6 +137,15 @@ pub fn path_rename<M: MemorySize>(
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, .. } => {
Expand Down

0 comments on commit 7e4ca73

Please sign in to comment.