Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path_rename syscall failing #4121

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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