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

String.write(toFile:atomically:encoding:) fails even with atomically: false only on WasmKit #178

Closed
kateinoigakukun opened this issue Mar 24, 2025 · 6 comments · Fixed by #180

Comments

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Mar 24, 2025

Reproduction steps

$ swift package init --name Check --type executable
$ cat <<EOS > Sources/main.swift
import Foundation
let text="test"
do {
  try text.write(toFile: "test.txt", atomically: false, encoding:.utf8)
} catch {
  print("Error: \(error)")
}
EOS
$ swift build --swift-sdk $SWIFT_SDK_ID
$ wasmkit-cli run --dir . .build/debug/Check.wasm
Error: Error Domain=NSCocoaErrorDomain Code=512 "(null)"UserInfo={NSFilePath=test.txt, NSURL=test.txt -- file:///}

wasmtime run --dir . .build/debug/Check.wasm succeeded without throwing the exception.

@kateinoigakukun kateinoigakukun changed the title String.write(toFile:, atomically:, encoding:) fails even with atomically: false only on WasmKit String.write(toFile:atomically:encoding:) fails even with atomically: false only on WasmKit Mar 24, 2025
@kkebo
Copy link
Contributor

kkebo commented Mar 25, 2025

try text.write(toFile: "test.txt", atomically: true, encoding:.utf8)

Probably you meant to write atomically: false?

@kkebo
Copy link
Contributor

kkebo commented Mar 25, 2025

This is because WasmKit does not support fd_sync yet.

String.write(toFile:atomically:encoding:) calls fsync here.

In fact, when I deleted this line and ran again, it succeeded in writing to a file without any errors.

@kateinoigakukun
Copy link
Member Author

Thanks, good finding!

@kkebo
Copy link
Contributor

kkebo commented Mar 25, 2025

I just implemented fd_sync in #180, but I don't know what kind of test to write for fd_sync...

@kkebo
Copy link
Contributor

kkebo commented Mar 26, 2025

I'm not sure that the current test suite includes a test case for fd_sync.

@kateinoigakukun
Copy link
Member Author

I don't think we can easily add such a test case for fd_sync. Let's follow https://github.com/WebAssembly/wasi-testsuite side future updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants