fix: populate ctime from actual filesystem stats instead of mtime fallback
All checks were successful
check / check (pull_request) Successful in 2m27s
All checks were successful
check / check (pull_request) Successful in 2m27s
Replace the mtime fallback for ctime in the scanner with platform-specific implementations that extract the real ctime from syscall.Stat_t: - macOS/Darwin: uses Birthtimespec (file birth/creation time) - Linux: uses Ctim (inode change time) - Falls back to mtime when syscall stats are unavailable (e.g. afero.MemMapFs) Also: - Document platform-specific ctime semantics in README - Document ctime restore limitations (cannot be set on either platform) - Add ctime field documentation to File model - Update README files table schema to match actual schema (adds ctime, source_path, link_target columns) - Add comprehensive tests for fileCTime on real files and mock FileInfo closes #13
This commit is contained in:
26
internal/snapshot/ctime_darwin.go
Normal file
26
internal/snapshot/ctime_darwin.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package snapshot
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fileCTime returns the file creation time (birth time) on macOS.
|
||||
//
|
||||
// On macOS/Darwin, "ctime" refers to the file's birth time (when the file
|
||||
// was first created on disk). This is stored in the Birthtimespec field of
|
||||
// the syscall.Stat_t structure.
|
||||
//
|
||||
// This differs from Linux where "ctime" means inode change time (the last
|
||||
// time file metadata was modified). See ctime_linux.go for details.
|
||||
//
|
||||
// If the underlying stat information is unavailable (e.g. when using a
|
||||
// virtual filesystem like afero.MemMapFs), this falls back to mtime.
|
||||
func fileCTime(info os.FileInfo) time.Time {
|
||||
stat, ok := info.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return info.ModTime()
|
||||
}
|
||||
return time.Unix(stat.Birthtimespec.Sec, stat.Birthtimespec.Nsec).UTC()
|
||||
}
|
||||
Reference in New Issue
Block a user