Skip to content

Saving a read-only file: hard error, or offer to overwrite? #373

Description

@PathGao

Is your feature request related to a problem? Please describe.

Saving over a read-only file used to behave differently per platform, because atomic_write replaces the file by renaming a temp file over it — and a rename is authorised by the directory's permissions, not the target's.

Before
macOS / Linux chmod 444 was ignored: the file was rewritten, and the read-only bit restored afterwards, so nothing showed the protection had been bypassed
Windows MoveFileExW refuses a read-only destination, so the save failed

A separate PR makes all three platforms refuse, which stops the silent bypass and makes the behaviour consistent. The buffer stays dirty and a toast reports … is read-only, so nothing is lost.

Worth flagging: that removes a capability on macOS and Linux. Anyone who was editing a read-only file there and saving successfully now gets an error instead. It was arguably never correct — the app was overriding a protection the user set — but it is a user-visible change and you should be the one to decide it stands.

Describe the solution you'd like

VS Code prompts instead of failing: "Failed to save … the file is write protected" with Overwrite / Cancel, and Overwrite clears the bit, writes, and restores it. That is friendlier than a dead end, since the user usually knows exactly why the file is read-only.

Describe alternatives you've considered

  • Keep the plain error (what the PR does). Nothing more to build, and the message names the cause.
  • Prompt to overwrite. Needs a distinguishable error code from the backend, a confirmation in the frontend, and a force path through the save command — a small but real UI contract, which is why it is not bundled into a fix PR.
  • Show read-only state in the UI before the save is attempted, so the user is not surprised at save time. Could stand alone or accompany either option above.

Happy to implement whichever you prefer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting decisionNeeds a product-direction call from the maintainer before work can startenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions