fs.v

1.2 KB · raw

1//! Filesystem facts the walk needs: kind, size, mode and nanosecond times.2//!3//! V's own `os.Stat` reports mtime in whole seconds, which is too coarse for4//! the file cache — a file edited twice inside one second would keep a stale5//! hash and the next save would record the wrong content. `vendor/shim` gives6//! the nanosecond times and tells symlinks apart from files in one call.78module snapshot910#flag -I@VMODROOT/vendor/shim11#flag @VMODROOT/vendor/shim/koh_stat.c12#include "koh_stat.h"1314pub struct C.koh_stat {15	size     i6416	mtime_ns i6417	ctime_ns i6418	mode     u3219	kind     int20}2122fn C.koh_lstat(path &char, out &C.koh_stat) int2324pub enum Kind {25	missing26	file27	dir28	symlink29	other30}3132pub struct Stat {33pub:34	size     i6435	mtime_ns i6436	ctime_ns i6437	mode     u3238	kind     Kind39}4041pub fn lstat(path string) ?Stat {42	mut raw := C.koh_stat{}43	if C.koh_lstat(unsafe { &char(path.str) }, &raw) == 0 {44		return none45	}46	return Stat{47		size:     raw.size48		mtime_ns: raw.mtime_ns49		ctime_ns: raw.ctime_ns50		mode:     raw.mode51		kind:     match raw.kind {52			1 { .file }53			2 { .dir }54			3 { .symlink }55			else { .other }56		}57	}58}5960pub fn is_executable(mode u32) bool {61	return mode & 0o111 != 062}