Repository navigation
Keep the file mode when formatting in place - #1286
Merged
Merged
Conversation
lenamonj
requested review from
allevato,
dylansturg,
hamishknight,
hborla and
rintaro
as code owners
September 6, 2026 09:06
Member
|
The implementation looks fine to me. But could you write some test cases? |
The test target depends on the SwiftFormat library and cannot reach the executable target, so the read, write and restore moved into an @_spi(Internal) Data extension that FormatFrontend calls. The tests cover 0600, 0444 and 0755 and a file that did not exist; without the restore all three come back 0644.
Contributor
Author
|
Added tests. They cover 0600, 0444 and 0755 files keeping their mode after the write, with the content replaced, and a file that did not exist; without the restore all three come back 0644. Because SwiftFormatTests depends on the SwiftFormat library and cannot reach the executable target, the read, write and restore moved into an @_spi(Internal) Data extension in the library that FormatFrontend calls. Compiled out on Windows. |
rintaro
approved these changes
Sep 9, 2026
Member
|
Thank you Jeff! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
swift-format format --in-placewrites withData.write(to:options:.atomic), which replaces the file rather than rewriting it, so the result is a new file created at the process umask. A source file the user had at 0600 came back 0644, and a 0444 one lost its read-only bit.The mode is read before the write and restored after it.
On main, formatting a 0600, 0444 or 0755 file in place leaves it at 0644; with this change each keeps its mode.