abla/sys/linux/fs

Generated from source.

Import with import "abla/sys/linux/fs".

Source: abla/sys/linux/fs/entry.ab

Path (class)

class Path(val text: string)

Stores path spelling text as given. Constructing a path does not query the filesystem.

FileInfo (class)

class FileInfo(
    val path: Path,
    val kind: int,
    val size: int,
    val revision: int,
    val inode: int = 0,
    val changed: int = 0
)

Metadata for path. Kind 0 means unavailable, 1 regular file, 2 directory, 3 another kind, and 4 symbolic link. size is in bytes and is -1 on failure. revision and changed are modification and status-change times in nanoseconds since the Unix epoch. Times and inode are zero when unavailable.

FileInfo.exists (method)

fun exists(): bool

Returns true when metadata was found.

FileInfo.isFile (method)

fun isFile(): bool

Returns true for a regular file.

FileInfo.isDirectory (method)

fun isDirectory(): bool

Returns true for a directory.

FileWatch (class)

class FileWatch(
    val paths: array<Path>,
    var revisions: array<int>,
    var fingerprints: array<string> = []
)

fingerprints (what watchFiles records) catches a rewrite inside one clock tick, which the modification time alone misses; a watch built with only revisions compares those.

path (fun)

fun path(value: string): Path

Returns a Path holding value without normalization or filesystem access.

linuxFileInfo (fun)

fun linuxFileInfo(filePath: Path): FileInfo

Returns metadata for filePath, following symbolic links. A failed lookup returns kind 0.

currentDirectory (fun)

trusted fun currentDirectory(): Path

Returns the process working directory, or a path containing . when the lookup fails.

homePath (fun)

trusted fun homePath(): Path?

HOME if set and nonempty, otherwise the effective uid's /etc/passwd home (on Windows, USERPROFILE: it has no /etc/passwd).

Path.child (extension fun)

fun Path.child(name: string): Path

Appends name to the path, inserting a separator if needed. Does not normalize or check the result.

Path.parent (extension fun)

fun Path.parent(): Path

Returns the lexical parent, ignoring trailing slashes. A single relative component has parent ., and the root has parent /.

Path.name (extension fun)

fun Path.name(): string

Returns the final path component after ignoring trailing separators, or an empty string if no component exists.

Path.extension (extension fun)

fun Path.extension(): string

Returns the final component's suffix after its last dot. Returns an empty string for no suffix, a leading dot alone, or a trailing dot.

Path.isAbsolute (extension fun)

fun Path.isAbsolute(): bool

Returns true if the path has an absolute root under the host's path rules.

Path.normalized (extension fun)

fun Path.normalized(): Path

The lexical normal form: no repeated separators or "." names, ".." folded in; the file system is not consulted.

Path.components (extension fun)

fun Path.components(): array<string>

The names after the root, in order.

Path.info (extension fun)

fun Path.info(): FileInfo

Returns metadata for the path, following symbolic links. Kind 0 indicates a failed lookup.

Path.linkInfo (extension fun)

fun Path.linkInfo(): FileInfo

What the path names itself: a symbolic link is not followed, and is kind 4 with the size of its target's name.

Path.revision (extension fun)

fun Path.revision(): int

Returns the modification time in nanoseconds since the Unix epoch, or 0 when metadata is unavailable.

Path.exists (extension fun)

fun Path.exists(): bool

Returns true when the path can be queried. Follows symbolic links, so a dangling link returns false.

Path.readText (extension fun)

fun Path.readText(): string

Reads the full contents of a regular file as bytes. Returns an empty string for an empty file, a nonregular file, or a failed lookup, open, or read.

FileReadResult (class)

class FileReadResult(
    val text: string,
    val succeeded: bool,
    val errorCode: int
)

A file's contents, or why they could not be read: succeeded is false with the system's error number (2: the file does not exist, 13: permission denied, 21: a directory), unlike readText's "" for every failure.

Path.readTextResult (extension fun)

fun Path.readTextResult(): FileReadResult

Opens the path and reads through EOF. Returns the bytes and success flag, or an empty string and a positive system error code. A directory is reported with error 21.

linuxFileSync (fun)

trusted fun linuxFileSync(descriptor: int): bool

Flushes the file or directory behind descriptor to its device (fsync). True when it succeeded; false for a bad descriptor or a failure (a file system that cannot sync one). The caller owns the descriptor.

linuxReadAtDescriptor (fun)

trusted fun linuxReadAtDescriptor(descriptor: int, offset: int, capacity: int, var result: SocketReceiveResult): void

Reads up to capacity bytes at offset (pread: the file position is not read or moved) into the reusable result: status is the count read (text holds the bytes, as an exactly sized string), 0 at the end of the file (an empty text), or -errno (-9 for a bad descriptor; -22 with nothing read for an offset below 0 and for a capacity outside 1..16777216). An interrupted read is retried. The caller owns the descriptor.

linuxWriteAll (fun)

trusted fun linuxWriteAll(descriptor: int, contents: string): bool

Writes all contents to the open descriptor. Returns false on an error or a write that made no progress. The caller owns the descriptor.

Path.createDirectories (extension fun)

fun Path.createDirectories(mode: int = 0o777): bool

Attempts to create every path component with mode filtered by the process umask. Returns false on a mkdir error other than already exists. Existing components are accepted without checking their kind.

Path.createParentDirectories (extension fun)

fun Path.createParentDirectories(): bool

Creates the parent path with the default directory mode. Returns false on a mkdir error other than already exists.

Path.writeText (extension fun)

trusted fun Path.writeText(contents: string, mode: int = 0o666): bool

Creation mode defaults to 0o666; existing files keep their permissions.

Path.appendText (extension fun)

trusted fun Path.appendText(contents: string): bool

Append is a separate operation so buffered portable writers can flush in bounded chunks without retaining an open target-specific descriptor.

Path.writeTextAtomic (extension fun)

trusted fun Path.writeTextAtomic(contents: string, mode: int = 0o666): bool

New files use mode (default 0o666), filtered by umask. A replacement inherits the existing mode on its empty temporary FD before any write.

Path.createExclusive (extension fun)

trusted fun Path.createExclusive(contents: string = "", mode: int = 0o600): bool

Creates the file with these contents and permissions, failing if anything is there already, so a secret is never readable by others on the way or written over what another process made.

Path.setPermissions (extension fun)

trusted fun Path.setPermissions(mode: int): bool

chmod. Permission bits use octal, for example 0o700 or 0o600.

Path.permissions (extension fun)

trusted fun Path.permissions(): int

The permission bits (for example 0o700), or -1 when the path doesn't exist. A symbolic link is followed.

Path.linkTo (extension fun)

trusted fun Path.linkTo(target: string): bool

Makes this path a symbolic link to target, which is stored as written.

Path.linkTarget (extension fun)

trusted fun Path.linkTarget(): string

What this symbolic link holds, or "" when it isn't one.

FileLock (class)

class FileLock(val descriptor: int)

An advisory lock on a file (flock), across processes. It goes when the holding process does. What this process starts inherits it only when asked, and then it lasts until they have gone too.

Path.fileLock (extension fun)

fun Path.fileLock(inherited: bool = false): FileLock

A lock on this path, creating the file. Not held yet; descriptor is negative when the file can't be opened.

FileLock.hold (extension fun)

trusted fun FileLock.hold(): bool

Waits for the lock.

FileLock.tryHold (extension fun)

trusted fun FileLock.tryHold(): bool

Takes the lock only if it's free.

FileLock.release (extension fun)

trusted fun FileLock.release(): bool

Unlocks the descriptor without closing it. Returns false for an invalid descriptor or unlock failure.

Path.moveTo (extension fun)

trusted fun Path.moveTo(destination: Path): bool

Creates parents of destination and renames this path there. Returns false if parent creation or rename fails, including a cross-filesystem rename.

fun Path.isSymbolicLink(): bool

Returns true if the path itself is a symbolic link. A failed lookup returns false.

FileInfo.modifiedMilliseconds (extension fun)

fun FileInfo.modifiedMilliseconds(): int

The modification time in milliseconds since the Unix epoch (0 when the path does not exist).

Path.copyTo (extension fun)

fun Path.copyTo(destination: Path): bool

Copies a file's bytes to destination, creating its directory.

Path.copyTreeTo (extension fun)

fun Path.copyTreeTo(destination: Path): int

Copies a directory and everything in it (or a file) to destination: directories are created, files copied, symbolic links followed. The number of files copied, or -1 when one could not be.

Path.removeTree (extension fun)

fun Path.removeTree(): bool

Removes a file, or a directory and everything in it. A symbolic link is removed itself, never what it points to. Whether the path is gone.

Path.remove (extension fun)

trusted fun Path.remove(): bool

Unlinks a file or symbolic link, or removes an empty directory. Returns false when removal fails, including when the path is already missing.

Path.entries (extension fun)

trusted fun Path.entries(): array<Path>

Returns immediate child paths in filesystem order, excluding dot and dot-dot. Returns an empty array if the directory cannot be opened and may return a partial list on a read error.

watchFiles (fun)

fun watchFiles(paths: array<Path>): FileWatch

Returns a snapshot of metadata and file fingerprints for later change detection.

watchFile (fun)

fun watchFile(filePath: Path): FileWatch

Returns a change-detection snapshot for one path.

FileWatch.changed (extension fun)

fun FileWatch.changed(): bool

Returns true if current metadata or fingerprints differ from the stored snapshot.

FileWatch.refresh (extension fun)

fun FileWatch.refresh(): void

Updates the stored metadata and fingerprints to reflect the current paths.

AnchoredPath (class)

class AnchoredPath(val text: string)

A path that was resolved to the real one it names, used without following a link again: the operations of Path, walked from the root with O_NOFOLLOW.

AnchoredPath.readTextResult (extension fun)

trusted fun AnchoredPath.readTextResult(): FileReadResult

The file's contents or why not, as Path.readTextResult, never through a link.

AnchoredPath.readText (extension fun)

fun AnchoredPath.readText(): string

The file's contents, or "" for any failure, as Path.readText.

AnchoredPath.info (extension fun)

trusted fun AnchoredPath.info(): FileInfo

The path's metadata without following a link at the end (kind 4 for one), as Path.info for a path with none.

AnchoredPath.exists (extension fun)

fun AnchoredPath.exists(): bool

Whether the path names anything.

AnchoredPath.revision (extension fun)

fun AnchoredPath.revision(): int

The modification time in nanoseconds, as Path.revision.

fun AnchoredPath.isSymbolicLink(): bool

Whether the path itself is a link.

AnchoredPath.entries (extension fun)

trusted fun AnchoredPath.entries(): array<Path>

The immediate child paths of a directory, as Path.entries.

AnchoredPath.createDirectories (extension fun)

trusted fun AnchoredPath.createDirectories(mode: int = 0o777): bool

Creates the directories of the path, as Path.createDirectories.

AnchoredPath.createParentDirectories (extension fun)

trusted fun AnchoredPath.createParentDirectories(): bool

Creates the directories that hold the path, as Path.createParentDirectories.

AnchoredPath.writeText (extension fun)

trusted fun AnchoredPath.writeText(contents: string, mode: int = 0o666): bool

Writes the file (created with mode, truncated), as Path.writeText.

AnchoredPath.appendText (extension fun)

trusted fun AnchoredPath.appendText(contents: string): bool

Appends to the file, as Path.appendText.

AnchoredPath.writeTextAtomic (extension fun)

fun AnchoredPath.writeTextAtomic(contents: string, mode: int = 0o666): bool

Replaces the file through a temporary beside it, as Path.writeTextAtomic.

AnchoredPath.replace (extension fun)

trusted fun AnchoredPath.replace(contents: string, mode: int, exactMode: bool, preserveExisting: bool, sync: bool): bool

The replacement writeTextAtomic and a build's own files share: a new temporary named like the file's with the process id, O_EXCL, written, optionally synced, renamed over the file. exactMode gives the file mode whatever it had; otherwise an existing file keeps its permissions when preserveExisting. Not for an absolute path or a system with no directory-relative calls: those use the Path implementation.

anchoredApplies (fun)

fun anchoredApplies(text: string): bool

Whether a relative path is walked by AnchoredPath (not an absolute path, not a system with no directory-relative calls): the build's own file writes use it then.

AnchoredPath.remove (extension fun)

trusted fun AnchoredPath.remove(): bool

Removes a file, a link or an empty directory, as Path.remove.

AnchoredPath.moveTo (extension fun)

trusted fun AnchoredPath.moveTo(destination: AnchoredPath): bool

Moves the path to destination (both read the same way), creating the destination's directories, as Path.moveTo.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.