From a884dd270fc1e55f6842fb047cf227f179d876b6 Mon Sep 17 00:00:00 2001 From: folbrich Date: Tue, 4 Aug 2026 09:40:01 +0200 Subject: [PATCH] Compare mtime with Equal() rather than == 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. --- localfs.go | 6 ++++-- localfs_other.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/localfs.go b/localfs.go index d9d4ff2..54f5306 100644 --- a/localfs.go +++ b/localfs.go @@ -145,7 +145,9 @@ func (fs *LocalFS) applyDirMetadata(n NodeDirectory) error { if err := fs.SetDirPermissions(n); err != nil { return err } - if n.MTime == time.Unix(0, 0) { + // Use Equal() rather than ==, which also compares the monotonic reading + // and the location and would miss an epoch mtime in a different location. + if n.MTime.Equal(time.Unix(0, 0)) { return nil } return r.Chtimes(n.Name, n.MTime, n.MTime) @@ -225,7 +227,7 @@ func (fs *LocalFS) CreateFile(n NodeFile) error { return err } - if n.MTime == time.Unix(0, 0) { + if n.MTime.Equal(time.Unix(0, 0)) { return nil } return r.Chtimes(n.Name, n.MTime, n.MTime) diff --git a/localfs_other.go b/localfs_other.go index 6ecf062..d3b8334 100644 --- a/localfs_other.go +++ b/localfs_other.go @@ -187,7 +187,7 @@ func (fs *LocalFS) CreateDevice(n NodeDevice) error { return fmt.Errorf("chmod %s: %w", n.Name, err) } } - if n.MTime == time.Unix(0, 0) { + if n.MTime.Equal(time.Unix(0, 0)) { return nil } return r.Chtimes(n.Name, n.MTime, n.MTime)