Skip to content

[wasi] File.Copy fails with "Function not implemented" when copying file metadata #134944

Description

@lewing

Description

On WASI, File.Copy and FileInfo.CopyTo always fail after copying the data:

System.IO.IOException : Function not implemented
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)

SystemNative_CopyFile (src/native/libs/System.Native/pal_io.c) copies the contents with its read/write fallback (no sendfile or fcopyfile on WASI), then copies metadata. The WASI build has HAVE_FCHMOD set, but WASI has no permission bits. fchmod very likely fails with ENOSYS, and the code only tolerates EPERM there, so the whole copy reports failure. futimens is also called and may fail the same way.

In the CoreCLR WASI library test runs on #134813 this fails 78 test cases in System.IO.Tests (the File.Copy/FileInfo.CopyTo paths, including the GB18030 file tests) and 3 in Microsoft.VisualBasic.Core.Tests. Microsoft.VisualBasic.FileIO.FileSystem copy APIs are affected too.

Proposed fix

On WASI, treat metadata copying as best effort: tolerate ENOSYS (and ENOTSUP) from fchmod and futimens in SystemNative_CopyFile the same way EPERM is tolerated, or skip the permission copy under TARGET_WASI. Confirm with a WASI run that fchmod is the call returning ENOSYS.

Note

This issue was drafted with the help of GitHub Copilot.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmWebAssembly architecturearea-System.IOos-wasiRelated to WASI variant of arch-wasm

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions