Module

std::fs

source

The file system by path: whole files read and written, what a path names, directories listed, made and removed, and files renamed. A path is any byte view, read through the capability that permits it (a Str under its domain, a static literal under StaticRead, a Buffer!'s bytes once opened), and copied with a NUL into a buffer freed when the call returns (std::io::c_string); a path holding a NUL is EINVAL. Every failure is a std::io::Error holding the errno. Nothing here prevents another process from changing the file system between two calls.

Types

FileKindWhat a path names: a regular file, a directory, or something else.
MetadataWhat stat(2) says of a path: the kind of what it names, after following symbolic links, and its size in bytes.
DirEntry!An entry of a directory: its name, which owns its bytes, and whether it is a directory.
Directory!An open directory: owns one DIR *, which close releases.

Functions

statusThe error of a C function (libc::fs) that returns 0 or an errno.
readThe whole of the file at path, read to its end through an Input! (Input!::read_to_end): a regular file, or a pipe or device (such as /dev/stdin or a shell's <(command)) read until it ends; a directory is EISDIR.
read_to_arenaread's bytes in the arena of cx, as text of it.
writeWrites contents to the file at path, created or emptied first, and frees it.
metadataWhat stat(2) says of path, following symbolic links.
path_existsWhether path names anything, following symbolic links.
canonicalizeThe absolute path with no ., .. or symbolic link that path names, which must exist (realpath(3)).
removeRemoves a file, or an empty directory (remove(3)).
renameRenames from to to, replacing what to named (rename(2)).
mkdirMakes the directory path, with mode 0777 less the umask; its parent must exist.
read_dirOpens the directory at path to list its entries.
is_dotWhether the NUL-terminated name is . or ...

Function declarations

fn statussource

fn status(code: i32) -> Result[(), Error] { ... }

The error of a C function (libc::fs) that returns 0 or an errno.

fn readsource

forall C, S where ReadBytes[C, S], Copy[S].
fn read(&cx: C, path: S) -> Result[Buffer!, Error] { ... }

The whole of the file at path, read to its end through an Input! (Input!::read_to_end): a regular file, or a pipe or device (such as /dev/stdin or a shell's <(command)) read until it ends; a directory is EISDIR. The file is closed whatever the read gave. A failure to read, or else to close, is the error: a read error takes precedence, and a failed close discards what was read.

fn read_to_arenasource

forall 'k, C, S, R where ReadBytes[C, S], Copy[S], Allocate[C -> 'k, R].
fn read_to_arena(&cx: C, path: S) -> Result[Str['k], Error] { ... }

read's bytes in the arena of cx, as text of it.

fn writesource

forall C, S where ReadBytes[C, S], Copy[S].
fn write(&cx: C, path: S, contents: Buffer!) -> Result[(), Error] { ... }

Writes contents to the file at path, created or emptied first, and frees it. The file is closed whatever the write gave. A failure to write, or else to close, is the error: a write error takes precedence (Output!::finish).

fn metadatasource

forall C, S where ReadBytes[C, S], Copy[S].
fn metadata(&cx: C, path: S) -> Result[Metadata, Error] { ... }

What stat(2) says of path, following symbolic links.

fn path_existssource

forall C, S where ReadBytes[C, S], Copy[S].
fn path_exists(&cx: C, path: S) -> Result[bool, Error] { ... }

Whether path names anything, following symbolic links. It does not when metadata fails with ENOENT, or with ENOTDIR for a path through something other than a directory; any other failure (EACCES, ELOOP, EIO, ...) says nothing about whether it does, and is the error.

fn canonicalizesource

forall C, S where ReadBytes[C, S], Copy[S].
fn canonicalize(&cx: C, path: S) -> Result[Buffer!, Error] { ... }

The absolute path with no ., .. or symbolic link that path names, which must exist (realpath(3)).

fn removesource

forall C, S where ReadBytes[C, S], Copy[S].
fn remove(&cx: C, path: S) -> Result[(), Error] { ... }

Removes a file, or an empty directory (remove(3)).

fn renamesource

forall C, F, T where ReadBytes[C, F], Copy[F], ReadBytes[C, T], Copy[T].
fn rename(&cx: C, from: F, to: T) -> Result[(), Error] { ... }

Renames from to to, replacing what to named (rename(2)). The two paths may be different kinds of view, read under the one capability cx.

fn mkdirsource

forall C, S where ReadBytes[C, S], Copy[S].
fn mkdir(&cx: C, path: S) -> Result[(), Error] { ... }

Makes the directory path, with mode 0777 less the umask; its parent must exist.

fn read_dirsource

forall C, S where ReadBytes[C, S], Copy[S].
fn read_dir(&cx: C, path: S) -> Result[Directory!, Error] { ... }

Opens the directory at path to list its entries.

fn is_dotsource

unsafe fn is_dot(name: *u8) -> bool { ... }

Whether the NUL-terminated name is . or ... Caller: name is a live NUL-terminated string.