Skip to content

Commit cbcd91b

Browse files
fix(shared/filesystem): make package build and tests pass on macOS (#2604)
The filesystem package referenced Linux-only fields on syscall.Stat_t (Atim, Ctim, Mtim), causing 'go test ./...' to fail on Darwin where those fields are named Atimespec/Ctimespec/Mtimespec. Refactor the OS-specific stat extraction into a small statTimes struct and an extractStatTimes helper, implemented per-platform behind build tags: - entry_linux.go (//go:build linux) uses Atim/Ctim/Mtim - entry_darwin.go (//go:build darwin) uses Atimespec/Ctimespec/Mtimespec This keeps production behavior unchanged on Linux while letting the package compile and its tests run on macOS, so contributors can run 'go test ./...' from packages/shared locally without cross-compiling. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent f63690d commit cbcd91b

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

packages/shared/pkg/filesystem/entry.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import (
77
"time"
88
)
99

10+
// statTimes holds platform-independent file timestamps and ownership info
11+
// extracted from a *syscall.Stat_t.
12+
type statTimes struct {
13+
atime time.Time
14+
ctime time.Time
15+
mtime time.Time
16+
uid uint32
17+
gid uint32
18+
}
19+
1020
func GetEntryFromPath(path string) (EntryInfo, error) {
1121
fileInfo, err := os.Lstat(path)
1222
if err != nil {
@@ -55,11 +65,12 @@ func GetEntryInfo(path string, fileInfo os.FileInfo) EntryInfo {
5565
}
5666

5767
if base := getBase(fileInfo.Sys()); base != nil {
58-
entry.AccessedTime = toTimestamp(base.Atim)
59-
entry.CreatedTime = toTimestamp(base.Ctim)
60-
entry.ModifiedTime = toTimestamp(base.Mtim)
61-
entry.UID = base.Uid
62-
entry.GID = base.Gid
68+
times := extractStatTimes(base)
69+
entry.AccessedTime = times.atime
70+
entry.CreatedTime = times.ctime
71+
entry.ModifiedTime = times.mtime
72+
entry.UID = times.uid
73+
entry.GID = times.gid
6374
} else if !fileInfo.ModTime().IsZero() {
6475
entry.ModifiedTime = fileInfo.ModTime()
6576
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build darwin
2+
3+
package filesystem
4+
5+
import "syscall"
6+
7+
func extractStatTimes(base *syscall.Stat_t) statTimes {
8+
return statTimes{
9+
atime: toTimestamp(base.Atimespec),
10+
ctime: toTimestamp(base.Birthtimespec),
11+
mtime: toTimestamp(base.Mtimespec),
12+
uid: base.Uid,
13+
gid: base.Gid,
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build linux
2+
3+
package filesystem
4+
5+
import "syscall"
6+
7+
func extractStatTimes(base *syscall.Stat_t) statTimes {
8+
return statTimes{
9+
atime: toTimestamp(base.Atim),
10+
ctime: toTimestamp(base.Ctim),
11+
mtime: toTimestamp(base.Mtim),
12+
uid: base.Uid,
13+
gid: base.Gid,
14+
}
15+
}

0 commit comments

Comments
 (0)