Skip to content

Compare mtime with Equal() rather than == - #381

Merged
folbricht merged 1 commit into
masterfrom
mtime-equal-comparison
Aug 4, 2026
Merged

Compare mtime with Equal() rather than ==#381
folbricht merged 1 commit into
masterfrom
mtime-equal-comparison

Conversation

@folbricht

Copy link
Copy Markdown
Owner

The LocalFS writers skip setting timestamps when the node's mtime is the epoch, treating that as "unset". The check used n.MTime == time.Unix(0, 0).

== on time.Time compares the wall clock, the monotonic reading and the location pointer, so it only matches an epoch mtime that happens to carry time.Local. The same instant in UTC or any other location falls through to Chtimes() and the entry gets its timestamps set to 1970 rather than being left alone.

Switched the three sites to Equal(), which compares the instant only:

  • localfs.goapplyDirMetadata() and CreateFile()
  • localfs_other.goCreateDevice()

Found by staticcheck's QF1009 (enabled by default in golangci-lint, but not in the staticcheck run in CI).

The "leave the timestamps alone if the mtime is the epoch" shortcut in
the LocalFS writers compared with ==, which on time.Time also compares
the monotonic reading and the location. An epoch mtime carrying a
location other than time.Local therefore didn't match, and the file or
directory had its timestamps set to 1970 instead of being left as
written.

Use Equal(), which compares the instant only.
@folbricht
folbricht merged commit 25af1d8 into master Aug 4, 2026
3 checks passed
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.

1 participant