Skip to content

Commit f69b420

Browse files
committed
fix: 修复macOS构建
1 parent 85618d0 commit f69b420

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build darwin
2+
3+
package log_watcher
4+
5+
import (
6+
"os"
7+
"syscall"
8+
"time"
9+
)
10+
11+
// getWindowsCreationTime on macOS returns the file's birth time (true creation time)
12+
func getWindowsCreationTime(path string, info os.FileInfo) time.Time {
13+
if info == nil {
14+
return time.Time{}
15+
}
16+
17+
sys := info.Sys()
18+
if sys == nil {
19+
return info.ModTime()
20+
}
21+
22+
stat, ok := sys.(*syscall.Stat_t)
23+
if !ok {
24+
return info.ModTime()
25+
}
26+
27+
// macOS supports Birthtimespec which is the true file creation time
28+
return time.Unix(stat.Birthtimespec.Sec, stat.Birthtimespec.Nsec)
29+
}

utils/ai_assistant2/log_watcher/ctime_unix.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !windows
1+
//go:build linux
22

33
package log_watcher
44

@@ -8,8 +8,7 @@ import (
88
"time"
99
)
1010

11-
// getWindowsCreationTime on non-Windows systems returns the best available creation time
12-
// On Linux/macOS, this uses ctime (status change time) as a proxy for creation time
11+
// getWindowsCreationTime on Linux returns ctime (status change time) as a proxy for creation time
1312
func getWindowsCreationTime(path string, info os.FileInfo) time.Time {
1413
if info == nil {
1514
return time.Time{}
@@ -25,10 +24,6 @@ func getWindowsCreationTime(path string, info os.FileInfo) time.Time {
2524
return info.ModTime()
2625
}
2726

28-
// Try to get birth time (creation time) on systems that support it
29-
// On macOS (darwin), Birthtimespec contains the creation time
30-
// On Linux, we fall back to ctime
31-
3227
// Use ctime (status change time) as a proxy
3328
// Note: ctime is updated when file metadata changes, not true creation time
3429
return time.Unix(stat.Ctim.Sec, stat.Ctim.Nsec)

0 commit comments

Comments
 (0)