Skip to content

Reject directories in read_file and apply the requested mode on write_file overwrite - #478

Open
warun7 wants to merge 1 commit into
kernel:mainfrom
warun7:fix/fs-read-dir-and-write-mode
Open

warun7 wants to merge 1 commit into
kernel:mainfrom
warun7:fix/fs-read-dir-and-write-mode

Conversation

@warun7

@warun7 warun7 commented Oct 19, 2026 •

Copy link
Copy Markdown

Fixes #477.

Summary

  • GET /fs/read_file: return 400 "path is a directory" when the path is a directory. Before, it sent 200 and the body failed on its first read.
  • PUT /fs/write_file: when mode is given, set it with f.Chmod after opening the file. OpenFile applies the permission only on create and through the umask, so an overwrite kept the old mode and 777 became 755. Without mode, an overwrite still keeps the file's current mode.

No API or spec changes: read_file already documents a 400 response.

Tests

  • TestReadFileDirectory: a directory path returns ReadFile400JSONResponse.
  • TestWriteFileModeOnOverwrite covers four cases:
    • the default is 644
    • an overwrite with 755 applies 755
    • 777 is not narrowed by the umask
    • an overwrite without mode keeps the current mode
  • Both tests fail on main and pass with this change.
  • cd server && go test ./cmd/api/api/ -run 'File|Fs|Upload|Download|Dir|Zip|Zstd' passes, and go vet and gofmt are clean.

Note

Low Risk
Localized filesystem handler fixes with targeted tests; no auth or API contract changes beyond aligning behavior with documented 400 responses.

Overview
Fixes filesystem API edge cases on read and write without changing the OpenAPI surface.

ReadFile now stats the opened path and returns 400 with "path is a directory" when the target is a directory, instead of streaming a 200 response whose body errors on first read.

WriteFile calls Chmod with the requested mode when the mode query param is set, so overwrites honor the explicit permission (including modes that would be masked on create) while overwrites without mode still preserve the existing file mode.

Adds TestReadFileDirectory and TestWriteFileModeOnOverwrite to lock in default 644, explicit 755/777 on overwrite, and unchanged mode when mode is omitted.

Reviewed by Cursor Bugbot for commit 36aade9. Bugbot is set up for automated code reviews on this repo. Configure here.

…_file overwrite

GET /fs/read_file on a directory returned 200 with a body that failed on the first read. It now returns 400 "path is a directory".

PUT /fs/write_file passed mode only to OpenFile, which applies it when creating the file and through the umask. Overwriting an existing file kept its old mode, and mode=777 became 755. An explicit mode is now set on the file with Chmod; without one, an overwrite keeps the current mode.
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.

fs: read_file returns 200 for a directory, and write_file ignores mode on overwrite

1 participant