//! Filesystem facts the walk needs: kind, size, mode and nanosecond times. //! //! V's own `os.Stat` reports mtime in whole seconds, which is too coarse for //! the file cache — a file edited twice inside one second would keep a stale //! hash and the next save would record the wrong content. `vendor/shim` gives //! the nanosecond times and tells symlinks apart from files in one call. module snapshot #flag -I@VMODROOT/vendor/shim #flag @VMODROOT/vendor/shim/koh_stat.c #include "koh_stat.h" pub struct C.koh_stat { size i64 mtime_ns i64 ctime_ns i64 mode u32 kind int } fn C.koh_lstat(path &char, out &C.koh_stat) int pub enum Kind { missing file dir symlink other } pub struct Stat { pub: size i64 mtime_ns i64 ctime_ns i64 mode u32 kind Kind } pub fn lstat(path string) ?Stat { mut raw := C.koh_stat{} if C.koh_lstat(unsafe { &char(path.str) }, &raw) == 0 { return none } return Stat{ size: raw.size mtime_ns: raw.mtime_ns ctime_ns: raw.ctime_ns mode: raw.mode kind: match raw.kind { 1 { .file } 2 { .dir } 3 { .symlink } else { .other } } } } pub fn is_executable(mode u32) bool { return mode & 0o111 != 0 }