Skip to content

fix(remotefs): treat PosixFile handles opened with O_RDWR as writable - #487

Open
blacksoxx wants to merge 1 commit into
k0sproject:mainfrom
blacksoxx:posixfile-rdwr-writable
Open

blacksoxx wants to merge 1 commit into
k0sproject:mainfrom
blacksoxx:posixfile-rdwr-writable

Conversation

@blacksoxx

Copy link
Copy Markdown

PosixFile.isWritable tested the O_WRONLY bit, but O_RDWR is a separate access mode (2), not a value that includes O_WRONLY (1). A file opened for reading and writing on a PosixFS was readable and not writable, so every Write and CopyFrom on it failed with "file ... is not open for writing". remotefs.CreateTemp, which opens with O_RDWR|O_CREATE|O_EXCL and documents the file as open for reading and writing, returned a handle that could not be written on POSIX hosts, and OpenFile with O_RDWR had the same problem. WinFS handles O_RDWR correctly, and Upload and WriteFile open with O_WRONLY, so they were not affected.

isWritable now compares the access mode, flags & (O_RDONLY|O_WRONLY|O_RDWR), and isReadable is written the same way. A table test covers the access modes, including O_RDWR, and a closed file.

The O_APPEND position handling noted in the issue is left for a separate change.

Fixes #481

isWritable tested the O_WRONLY bit, but O_RDWR is a separate access
mode, so a file opened for reading and writing rejected every Write
and CopyFrom. CreateTemp and OpenFile with O_RDWR on a PosixFS were
affected; WinFS already handled O_RDWR. Compare the access mode
instead of a single bit, and express isReadable the same way.

Signed-off-by: Youssef Omar Bouden <youssef.bouden2002@gmail.com>
@kke
kke requested a balanced review from Copilot October 12, 2026 11:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation directly fixes the reported behavior and includes focused regression coverage.

0 open findings

What changed in this PR

Fixes POSIX file access-mode detection so O_RDWR handles support both reading and writing.

Changes:

  • Adds a shared access-mode helper.
  • Corrects readable/writable checks.
  • Adds coverage for access modes and closed files.
File Description
remotefs/​posixfile.go Corrects POSIX access-mode handling.
remotefs/​posixfile_internal_test.go Tests access modes and closed handles.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

remotefs: PosixFile opened with O_RDWR rejects every write

2 participants