Repository navigation
Fix io.open w+ failing on a file that does not exist - #365
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The narrow mapping change implements the required semantics, and the regression test covers creation and truncation with no identified blocking issues.
No open issues 🎉
What changed in this PR
Fixes io.open write-update mode so it creates missing files and truncates existing files while preserving read/write access.
Changes:
- Maps
LuaFileOpenMode.WriteUpdatetoFileMode.Createinstead ofFileMode.Truncate. - Adds a regression test covering creation, writing, seeking, reading, and truncation on reopening.
| File | Description |
|---|---|
| tests/Lua.Tests/IOTests.cs | Adds regression coverage for w+ file behavior. |
| src/Lua/IO/FileSystem.cs | Corrects the write-update file mode mapping. |
Review effort: Balanced
|
Thank you for the w+ creation fix and the regression test! Your original commit has been merged through #368 with its authorship preserved. The broader seek/write checks also uncovered an adjacent existing issue: w+ was classified as append mode, so writes after a seek went to the end of the file. We fixed that in a follow-up and expanded coverage for both w+ and w+b, while checking that a+ and a+b still append after a seek. The combined changes passed local tests and Linux CI. |
io.open(path, "w+")/"w+b"threw when the file did not exist.LuaFileOpenMode.WriteUpdatewas mapped toFileMode.Truncate, which requires an existing file. Lua'sw+creates the file if needed and truncates it otherwise, so it is now mapped toFileMode.Create(stillFileAccess.ReadWrite).Verification
OpenWritePlus_CreatesMissingFileAndTruncatesExisting(create, write, seek, read back, reopen and check it is truncated) fails onmainand passes with the change.dotnet test tests/Lua.Tests/Lua.Tests.csproj -c Release --filter "TestCategory!=ExpectedFailure": 611 passed, 0 failed (610 onmain+ 1 new).dotnet csharpier check .is clean.