-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: Truncate() on a non-existent file will create a file on Windows #58977
Comments
(CC @golang/windows) |
Why should Windows program behave the same as Linux? Alex |
@alexbrainman that's kind of the point of the os package. |
If you read I suspect that authors of the Alex |
@alexbrainman luckily, we're not bound by the underspecified documentation. |
The behavior should be consistent across platforms unless there is a well-defined platform-specific behavior that would lead a Go user to expect otherwise. In this case, the difference in behavior is because of explicit flags passed to It seems to me that the behavior should be made consistent, although it may need a |
AFAIK, the only well-defined Windows api that truncate files referenced by file name and not by handler is $ fsutil file seteof foo.txt 2
Error: The system cannot find the file specified. |
Change https://go.dev/cl/477215 mentions this issue: |
Change https://go.dev/cl/498600 mentions this issue: |
Also mention WTF-8 support in the syscall package. For #32558 For #58977 For #59971 Change-Id: Id1627889b5e498add498748d9bfc69fb58030b35 Reviewed-on: https://go-review.googlesource.com/c/go/+/498600 Reviewed-by: Eli Bendersky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
If you truncate a non-existent file with os.Truncate on Linux a no such file or directory error is given. On Windows, however, a file will be created and the error will be nil.
Here is a link to an application https://go.dev/play/p/SoUjXmpP0Ii that behaves as expected on Linux. It correctly gives a no such file or directory error. However, if you run it on Windows, you will not see any errors and a file will be created. Here is the test code to run.
What did you expect to see?
The behavior on Windows should be the same as it is on Linux. Since no file exists, it should give a no such file or directory error.
What did you see instead?
On Windows, no error is given and a file is created.
The text was updated successfully, but these errors were encountered: