Skip to content

cmd/cue: cue fix writing files with zero changes updates mtime for no reason #3884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stevenj opened this issue Apr 9, 2025 · 1 comment
Labels

Comments

@stevenj
Copy link

stevenj commented Apr 9, 2025

What version of CUE are you using (cue version)?

$ cue version

cue version 0.12.0

go version go1.24.1
      -buildmode pie
       -compiler gc
       -trimpath true
  DefaultGODEBUG asynctimerchan=1,gotestjsonbuildtext=1,gotypesalias=0,httpservecontentkeepheaders=1,multipathtcp=0,randseednop=0,rsa1024min=0,tls3des=1,tlsmlkem=0,x509keypairleaf=0,x509negativeserial=1,x509rsacrt=0,x509usepolicies=0
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.12.0

Does this issue reproduce with the latest stable release?

I guess so. There is no noted fix in the changelog for 0.12.1.

What did you do?

$ echo "package test" > test.cue
$ cue fix test.cue
$ cp test.cue test2.cue
$ touch -d "2 days ago" test.cue
$ ls -al test*.cue
-rw-r--r-- 1 steven steven 13 Apr  7 08:38 test.cue
-rw-r--r-- 1 steven steven 13 Apr  9 08:38 test2.cue
$  diff -q test.cue test2.cue; echo $?
0
$ cue fix test.cue
$ ls -al test*.cue
-rw-r--r-- 1 steven steven 13 Apr  9 08:39 test.cue
-rw-r--r-- 1 steven steven 13 Apr  9 08:38 test2.cue
$  diff -q test.cue test2.cue; echo $?
0

What did you expect to see?

The modified timestamp of the file would not change the second time cue fix was run on it because the contents did not change.

What did you see instead?

The contents did not change, but the modified timestamp of the file was set to the time cue fix was run.

@stevenj stevenj added NeedsInvestigation Triage Requires triage/attention labels Apr 9, 2025
@mvdan
Copy link
Member

mvdan commented Apr 9, 2025

Thanks - we should probably not write/update files if the contents are entirely unchanged. This applies to any rewrite commands - cue fmt, cue fix, cue trim, cue mod tidy, and so on.

@mvdan mvdan added NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Apr 9, 2025
@mvdan mvdan changed the title cue fix change mtime of files even if the file has nothing to fix. cmd/cue: cue fix writing files with zero changes updates mtime for no reason Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants