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 d920941
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions lib/wasix/src/syscalls/wasi/path_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,26 @@ 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 {
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() {
Expand All @@ -151,15 +143,6 @@ pub fn path_rename<M: MemorySize>(
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, .. } => {
Expand Down

0 comments on commit d920941

Please sign in to comment.