kitty/kittens/dnd/birth_time_linux.go
Kovid Goyal 9575920aab
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Cleanup previous PR
Track move source identities in drop_status rather than parsed_uri, and
also compare birth times where available, so that a replacement reusing
the inode number of a deleted source is not removed. Clarify the
changelog entry.
2026-10-30 18:28:40 +05:30

32 lines
789 B
Go

package dnd
import (
"os"
"time"
"golang.org/x/sys/unix"
)
// Return the birth time of the file at path, which must be the file
// described by info, or the zero time if it is unknown.
func birth_time(path string, info os.FileInfo) time.Time {
var sx unix.Statx_t
for {
err := unix.Statx(unix.AT_FDCWD, path, unix.AT_SYMLINK_NOFOLLOW, unix.STATX_INO|unix.STATX_BTIME, &sx)
if err == nil {
break
}
if err != unix.EINTR {
return time.Time{}
}
}
if sx.Mask&unix.STATX_BTIME == 0 {
return time.Time{}
}
// The path may have been replaced since info was obtained
dev, ino, err := file_identity(info)
if err != nil || ino != sx.Ino || dev != unix.Mkdev(sx.Dev_major, sx.Dev_minor) {
return time.Time{}
}
return time.Unix(sx.Btime.Sec, int64(sx.Btime.Nsec))
}