-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/cmd: avoid overwriting formatted files in cue fmt
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, their contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. To fix this, we buffer the original/formatted bytes. If the result is exactly the same, the file is not written to. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
- Loading branch information
Showing
3 changed files
with
56 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Verify that cue fmt does not write to files | ||
# if they are already formatted | ||
mod-time formatted.cue | ||
cp stdout mod-time.txt | ||
exec cue fmt formatted.cue | ||
mod-time formatted.cue | ||
cmp stdout mod-time.txt | ||
|
||
-- formatted.cue -- | ||
a: 1 |