Skip to content

Conversation

@cdmurph32
Copy link
Contributor

@cdmurph32 cdmurph32 commented Jan 9, 2026

When PR #147572 switched WASI to use Unix-style filesystem APIs, the open_to_and_set_permissions function for WASI was implemented to call OpenOptions::new().open() without setting any access mode flags.

This causes std::fs::copy to fail with the error:
"must specify at least one of read, write, or append access"

The fix is to explicitly set .write(true), .create(true), and .truncate(true) on the OpenOptions, matching the behavior of the non-WASI Unix implementation but without the permission handling that WASI doesn't support.

Minimal reproduction:

    fn main() {
        std::fs::write("/src.txt", b"test").unwrap();
        match std::fs::copy("/src.txt", "/dst.txt") {
            Ok(_) => println!("PASS: fs::copy works!"),
            Err(e) => println!("FAIL: {}", e),
        }
    }
# Compile and run:
rustc +nightly --target wasm32-wasip2 test.rs -o test.wasm
wasmtime -S cli --dir . test.wasm

# Before fix: FAIL: must specify at least one of read, write, or append access
# After fix:  PASS: fs::copy works!

Note: The existing test library/std/src/fs/tests.rs::copy_file_ok would have caught this regression if the std test suite ran on WASI targets. Currently std tests don't compile for wasm32-wasip2 due to Unix-specific test code in library/std/src/sys/fd/unix/tests.rs.

Fixes the regression introduced in nightly-2025-12-10.

r? @alexcrichton

When PR rust-lang#147572 switched WASI to use Unix-style filesystem APIs, the
open_to_and_set_permissions function for WASI was implemented to call
OpenOptions::new().open() without setting any access mode flags.

This causes std::fs::copy to fail with the error:
"must specify at least one of read, write, or append access"

The fix is to explicitly set .write(true), .create(true), and
.truncate(true) on the OpenOptions, matching the behavior of the
non-WASI Unix implementation but without the permission handling
that WASI doesn't support.

Minimal reproduction:
    fn main() {
        std::fs::write("/src.txt", b"test").unwrap();
        match std::fs::copy("/src.txt", "/dst.txt") {
            Ok(_) => println!("PASS: fs::copy works!"),
            Err(e) => println!("FAIL: {}", e),
        }
    }

    # Compile and run:
    rustc +nightly --target wasm32-wasip2 test.rs -o test.wasm
    wasmtime -S cli --dir . test.wasm

    # Before fix: FAIL: must specify at least one of read, write, or append access
    # After fix:  PASS: fs::copy works!

Note: The existing test library/std/src/fs/tests.rs::copy_file_ok
would have caught this regression if the std test suite ran on WASI
targets. Currently std tests don't compile for wasm32-wasip2 due to
Unix-specific test code in library/std/src/sys/fd/unix/tests.rs.

Fixes the regression introduced in nightly-2025-12-10.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 9, 2026
@rust-log-analyzer

This comment has been minimized.

@cdmurph32 cdmurph32 marked this pull request as ready for review January 9, 2026 18:55
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@alexcrichton
Copy link
Member

@bors: r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 9, 2026

Unknown command ":". Run @bors help to see available commands.

@alexcrichton
Copy link
Member

@bors r+

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 9, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 9, 2026

📌 Commit 43c1db7 has been approved by alexcrichton

It is now in the queue for this repository.

@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2026
tgross35 added a commit to tgross35/rust that referenced this pull request Jan 9, 2026
Fix std::fs::copy on WASI by setting proper OpenOptions flags

When PR rust-lang#147572 switched WASI to use Unix-style filesystem APIs, the open_to_and_set_permissions function for WASI was implemented to call OpenOptions::new().open() without setting any access mode flags.

This causes std::fs::copy to fail with the error:
"must specify at least one of read, write, or append access"

The fix is to explicitly set .write(true), .create(true), and .truncate(true) on the OpenOptions, matching the behavior of the non-WASI Unix implementation but without the permission handling that WASI doesn't support.

Minimal reproduction:
```rs
    fn main() {
        std::fs::write("/src.txt", b"test").unwrap();
        match std::fs::copy("/src.txt", "/dst.txt") {
            Ok(_) => println!("PASS: fs::copy works!"),
            Err(e) => println!("FAIL: {}", e),
        }
    }
```
    # Compile and run:
    rustc +nightly --target wasm32-wasip2 test.rs -o test.wasm
    wasmtime -S cli --dir . test.wasm

    # Before fix: FAIL: must specify at least one of read, write, or append access
    # After fix:  PASS: fs::copy works!

Note: The existing test library/std/src/fs/tests.rs::copy_file_ok would have caught this regression if the std test suite ran on WASI targets. Currently std tests don't compile for wasm32-wasip2 due to Unix-specific test code in library/std/src/sys/fd/unix/tests.rs.

Fixes the regression introduced in nightly-2025-12-10.

r? @alexcrichton
rust-bors bot added a commit that referenced this pull request Jan 10, 2026
Rollup of 9 pull requests

Successful merges:

 - #149318 (Implement partial_sort_unstable for slice)
 - #150805 (Fix ICE in inline always warning emission.)
 - #150822 (Fix for ICE: eii: fn / macro rules None in find_attr())
 - #150853 (std: sys: fs: uefi: Implement File::read)
 - #150855 (std: sys: fs: uefi: Implement File::tell)
 - #150881 (Fix std::fs::copy on WASI by setting proper OpenOptions flags)
 - #150891 (Fix a trivial typo in def_id.rs)
 - #150892 (Don't check `[mentions]` paths in submodules from tidy)
 - #150894 (cg_llvm: add a pause to make comment less confusing)

r? @ghost
@rust-bors rust-bors bot merged commit c2f0209 into rust-lang:main Jan 10, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 10, 2026
rust-timer added a commit that referenced this pull request Jan 10, 2026
Rollup merge of #150881 - fix-wasi-fs-copy, r=alexcrichton

Fix std::fs::copy on WASI by setting proper OpenOptions flags

When PR #147572 switched WASI to use Unix-style filesystem APIs, the open_to_and_set_permissions function for WASI was implemented to call OpenOptions::new().open() without setting any access mode flags.

This causes std::fs::copy to fail with the error:
"must specify at least one of read, write, or append access"

The fix is to explicitly set .write(true), .create(true), and .truncate(true) on the OpenOptions, matching the behavior of the non-WASI Unix implementation but without the permission handling that WASI doesn't support.

Minimal reproduction:
```rs
    fn main() {
        std::fs::write("/src.txt", b"test").unwrap();
        match std::fs::copy("/src.txt", "/dst.txt") {
            Ok(_) => println!("PASS: fs::copy works!"),
            Err(e) => println!("FAIL: {}", e),
        }
    }
```
    # Compile and run:
    rustc +nightly --target wasm32-wasip2 test.rs -o test.wasm
    wasmtime -S cli --dir . test.wasm

    # Before fix: FAIL: must specify at least one of read, write, or append access
    # After fix:  PASS: fs::copy works!

Note: The existing test library/std/src/fs/tests.rs::copy_file_ok would have caught this regression if the std test suite ran on WASI targets. Currently std tests don't compile for wasm32-wasip2 due to Unix-specific test code in library/std/src/sys/fd/unix/tests.rs.

Fixes the regression introduced in nightly-2025-12-10.

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants