Import with #import "std/file_tree_linux".

PathKind :: enum { Missing = 0; File = 1; Directory = 2; Link = 3; Other = 4; }
PathInfo :: struct { kind: PathKind; owner_uid: u32; mode: s32; size: s64; modified: s64; modified_nanoseconds: u32; metadata_mask: u32; identity_valid: bool; inode: u64; changed: s64; changed_nanoseconds: u32; device_major: u32; device_minor: u32; }
PathQueryResult :: struct { info: PathInfo; valid: bool; missing: bool; error: s32; }

A failed query has zero info. Only ENOENT/ENOTDIR mean missing; error otherwise preserves the positive Linux errno (EINVAL for invalid text).

PathQuery :: (path: string, follow_links: bool) -> PathQueryResult

Follows links by default. Invalid text contains NUL or exceeds 4095 bytes.

PathStatus :: (path: string, follow_links: bool) -> PathInfo

The path's metadata, or zero info on any failure. Use PathQuery when the distinction between a missing path and another error matters.

FileSnapshot :: (path: string) -> PathInfo

A complete identity of a regular file without following its final symlink.

SameFileSnapshot :: (left: PathInfo, right: PathInfo) -> bool
IsFile :: (path: string) -> bool
IsDirectory :: (path: string) -> bool
SetPathMode :: (path: string, mode: s32) -> bool
JoinPath :: (directory: string, name: string) -> Text

DIRECTORY/NAME, or NAME alone when it is absolute or DIRECTORY is empty.

PathName :: (path: string) -> string

The last part of PATH, after its final slash.

PathParent :: (path: string) -> string

PATH without its last part: "." for a bare name, "/" for a root entry.

PathSuffix :: (path: string) -> string

The name's extension with its dot, as Python's Path.suffix: ".png".

PathStem :: (path: string) -> string

The name without its extension, as Python's Path.stem.

ResolvePath :: (path: string) -> Text

The absolute path with every link and dot resolved; empty when PATH does not exist.

CreateTemporaryDirectory :: (parent: string, prefix: string) -> Text

Atomically creates a unique private child of an existing caller-owned parent. The parent and its ancestors must stay at stable paths during the call. PREFIX is a single name component; six random characters follow it. Returns the canonical absolute child path, or empty on failure. The caller owns the returned allocation and directory cleanup with RemoveTree. Permissions are 0700, restricted by umask.

WorkingDirectory :: () -> Text
CreateDirectories :: (path: string, mode: s32) -> bool

Creates PATH and every missing parent folder; true when it exists as a folder afterwards.

FreeDirectoryNames :: (names: *Vec(string))

Release every independently owned name returned by ListDirectory and the vector storage, resetting the vector to empty. Do not mix borrowed strings or duplicate ownership into this vector. Empty, repeated and null calls are harmless; all borrowed views of its names expire at this call.

ListDirectory :: (path: string, names: *Vec(string)) -> bool

The names in a folder, without "." and "..", sorted by their bytes. Appends independently owned entry names in sorted order. The caller owns each nonempty string as well as the Vec; release both with FreeDirectoryNames. Failed scans append nothing.

RemoveTree :: (path: string) -> bool

Removes PATH and, for a folder, everything in it. Links are removed, never followed. True when nothing remains at PATH. All traversal scratch is freed.

CopyFile :: (source: string, target: string) -> bool

Copies a file's bytes and permission bits to TARGET, replacing it.

CopyTree :: (source: string, target: string) -> bool

Copies a folder and everything in it to TARGET, which is created; links inside are copied as links.

CopyFileNew :: (source: string, target: string) -> bool

Copy to an exclusively created private file, preserving permission bits on success. An incomplete file remains private. Links are copied as links. Failure may leave a partial new file; never removes a destination. Keep source and destination ancestors stable during copying.

CopyTreeNew :: (source: string, target: string) -> bool

Copy into a new directory under an existing parent, with exclusive child creation and links preserved. Reject self/descendant destinations, including aliases through symlink parents. Failure may leave a partial new tree, with no rollback deletion. Ancestors and source entries must remain stable.

ReplaceFile :: (path: string, text: string) -> bool

Replaces the file at PATH with TEXT so that readers see either the old or the new whole file: a private sibling file is written, synced and renamed over it. The new file keeps the old one's permission bits.

LockPath :: (path: string, exclusive: bool, wait: bool) -> s32

Opens (creating) the lock file at PATH and takes its flock: exclusive or shared, waiting or not. Returns the descriptor to UnlockPath, or -1 when the file cannot be opened or, without wait, another holder has it.

UnlockPath :: (fd: s32)
MatchName :: (name: string, pattern: string) -> bool

Whether NAME matches a shell wildcard PATTERN: * any run, ? one byte, [abc], [a-z] and [!abc] one byte of a set. Nothing else is special.

Source ↗ · All modules