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

renaming files through WASI does not work correctly since 3.2.0 #3945

Closed
nil-vr opened this issue Jun 2, 2023 · 1 comment · Fixed by #4121
Closed

renaming files through WASI does not work correctly since 3.2.0 #3945

nil-vr opened this issue Jun 2, 2023 · 1 comment · Fixed by #4121
Labels
priority-high High priority issue
Milestone

Comments

@nil-vr
Copy link

nil-vr commented Jun 2, 2023

Describe the bug

Since the 3.2.0-beta.1 release, renaming files through WASI does not work.

  1. If wasmer is invoked wasmer run --dir . broken-rename.wasm, path_rename when passed a file descriptor for /root cannot resolve paths relative to that file descriptor and returns NOENT.
  2. If wasmer is invoked wasmer run --dir root broken-rename.wasm, the previous problem with path_rename occurs, but also Rust's fs::rename starts returning the same error code. I'm guessing it tries to use a file handle for / and fails because / and /root are different filesystems.
wasmer 3.3.0 (5eeda45 2023-05-03)
binary: wasmer-cli
commit-hash: 5eeda455a4c3928cfc13760e3515020543d4cd58
commit-date: 2023-05-03
host: x86_64-pc-windows-msvc
compiler: singlepass,cranelift,llvm
rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-pc-windows-msvc
release: 1.68.0
LLVM version: 15.0.6

Steps to reproduce

This simple program works on wasmer 3.2.0-alpha.1 but fails on 3.2.0-beta.1 and later.

use std::fs::{self, File};
use std::os::fd::AsRawFd;

fn main() {
    unsafe {
        let dir = File::open("/root").unwrap();
        fs::write("/root/a", "a").unwrap();

        match wasi::path_rename(dir.as_raw_fd() as _, "a", dir.as_raw_fd() as _, "b") {
            Ok(_) => {
                eprintln!("path_rename passed.");
                fs::write("/root/a", "a").unwrap();
            }
            Err(e) => {
                eprintln!("path_rename failed: {e:?}");
            }
        }

        match fs::rename("/root/a", "/root/b") {
            Ok(_) => {
                eprintln!("fs::rename passed.");
            }
            Err(e) => {
                eprintln!("fs::rename failed: {e:?}");
            }
        }
    }
}

Expected behavior

Renaming a to b should work both times.

Actual behavior

a cannot be renamed to b because of NOENT errors.

Additional context

@ptitSeb
Copy link
Contributor

ptitSeb commented Jun 2, 2023

I can reproduce the issue with current master. I also checked that it was working with older version of wasmer (2.3 tested).

@ptitSeb ptitSeb added the priority-high High priority issue label Jun 6, 2023
@ptitSeb ptitSeb modified the milestones: v4.1, v4.0 Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-high High priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants