Skip to content

os: implement os.(*File).Truncate and os.Truncate #3699

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

Closed

Conversation

achille-roussel
Copy link
Contributor

This PR adds an implementation of os.(*File).Truncate and os.Truncate. The implementation is based on libc's truncate and ftruncate functions. I ported the tests from the Go standard library as well.

@achille-roussel
Copy link
Contributor Author

I'm investigating the issue reported by Linux / assert-test-linux; make test fails with:

--- FAIL: TestTest (0.00s)
    --- FAIL: TestTest/WASM (0.00s)
        --- FAIL: TestTest/WASM/Pass (0.30s)
            main_test.go:521: FAIL	github.com/tinygo-org/tinygo/tests/testing/pass	0.000s
            main_test.go:430: test error: could not compile: /home/achille_roussel/go/src/github.com/achille-roussel/tinygo/src/os/file_posix.go:19:17: Truncate not declared by package syscall
            main_test.go:433: test failed
        --- FAIL: TestTest/WASM/Fail (0.30s)
            main_test.go:521: FAIL	github.com/tinygo-org/tinygo/tests/testing/fail	0.000s
            main_test.go:451: test error: could not compile: /home/achille_roussel/go/src/github.com/achille-roussel/tinygo/src/os/file_posix.go:19:17: Truncate not declared by package syscall

Tho testing the os package directly seems to work:

$ ./build/tinygo test -target=wasi os
ok  	os	0.024s

Trying to figure out what is it that I don't understand about the difference between these two tests.

@dgryski
Copy link
Member

dgryski commented May 3, 2023

I believe on when building for Linux we use upstream's syscall package, but on other platforms we use the tinygo/src/syscall. That could lead to some of the issues you're seeing.

Maybe also a caching issue?

@aykevl
Copy link
Member

aykevl commented May 3, 2023

Tho testing the os package directly seems to work:

syscall_libc.go is only for WASI, not for js/wasm. Try -target=wasm to reproduce this locally.

@achille-roussel
Copy link
Contributor Author

I'm going to close this PR since tinygo has integrated the Go 1.21 changes where os.(*File).Truncate is implemented.

@achille-roussel achille-roussel deleted the wasi-truncate branch September 1, 2023 23:37
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 this pull request may close these issues.

3 participants