silk.system.file_time.

Cross-platform host file metadata and timestamp operations for caches and build tools.

When to use#

Use FileTime when a build system or cache manager needs a single-syscall size and modification-time lookup (meta), full modification and change timestamps (timestamps), or throttled hit-time refreshing (touchIfStale) across Linux, macOS, and Windows.

Details#

On GNU Linux and Darwin, operations delegate to silk.platform.native.file. On x86-64 MSVC Windows, operations delegate to silk.platform.windows.file_time (GetFileAttributesExW, GetFileInformationByHandleEx with FileBasicInfo, and SetFileTime opened with FILE_WRITE_ATTRIBUTES and full sharing). On hosts without native file timestamps (such as WASI, bare WebAssembly, or libc-free builds), queries return None and updates are no-ops.

Import as FileTime with import silk.system.file_time as FileTime.

Public declarations: 8.

FileTimestamp#

silk
pub struct FileTimestamp

One file timestamp as whole Unix seconds and subsecond nanoseconds.

Field seconds#

silk
pub seconds: i64

Whole seconds since 1970-01-01T00:00:00Z.

Field nanoseconds#

silk
pub nanoseconds: u32

Nanoseconds after seconds, in the range 0 through 999999999.

Implementation Copy for FileTimestamp#

silk
impl Copy for FileTimestamp

FileTimestamps#

silk
pub struct FileTimestamps

Both modification and status-change timestamps of a host file or directory.

Field modified#

silk
pub modified: FileTimestamp

Last data modification time (mtime on POSIX, LastWriteTime on Windows).

Field changed#

silk
pub changed: FileTimestamp

Last metadata or data change time (ctime on POSIX, ChangeTime on Windows).

Implementation Copy for FileTimestamps#

silk
impl Copy for FileTimestamps

FileMeta#

silk
pub struct FileMeta

Logical byte length, whole-second modification time, and directory flag read in one lookup.

Field bytes#

silk
pub bytes: u64

Logical byte length for files, or zero for directories.

Field modifiedSeconds#

silk
pub modifiedSeconds: i64

Whole-second last modification time since 1970-01-01T00:00:00Z.

Field isDirectory#

silk
pub isDirectory: bool

True when the entry is a directory.

Implementation Copy for FileMeta#

silk
impl Copy for FileMeta

meta#

silk
pub effect fn meta(path: &Path) -> Option<FileMeta>

Returns the logical size, modification time, and directory flag of path in one host lookup, or None when the path does not exist or the host has no native metadata API.

timestamps#

silk
pub effect fn timestamps(path: &Path) -> Option<FileTimestamps>

Returns both the modification (mtime) and status-change (ctime / ChangeTime) timestamps of path, or None when the path cannot be queried or the host has no native timestamp API.

modifiedSeconds#

silk
pub effect fn modifiedSeconds(path: &Path) -> Option<i64>

Returns the modification time of path in whole Unix seconds, or None when unavailable.

setModifiedSeconds#

silk
pub effect fn setModifiedSeconds(path: &Path, seconds: i64) -> bool

Sets the access and modification times of path to whole Unix seconds. Returns true when the update succeeded, or false when the path could not be updated or the host has no native timestamp API.

touchIfStale#

silk
pub effect fn touchIfStale(path: &Path, intervalSeconds: i64) -> ()

Refreshes the modification time of path to the current system time when its existing modification time is at least intervalSeconds old. Best effort: errors are ignored.

Category: System.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page