Module: io.dir

Source: ./io/dir.reef


Overview

io/dir - Directory operations

Provides functions for working with directories. Uses POSIX functions via C FFI.

create_dir/create_dir_all/remove_dir/change_dir return Result[bool, error.Error]: Ok(true) on success (the void-success convention — never Ok(false)). current_dir returns Result[string, error.Error]: Ok(path) on success ("" is a normal zero-length path, not a failure sentinel).

create_dir classifies via a dir_exists/stat.exists recheck: Err(AlreadyExists) if the path already exists, Err(NotFound) if its parent directory doesn't exist, Err(PermissionDenied) for any other reason (the dominant real-world cause once those two are ruled out).

create_dir_all (recursive mkdir -p) only fails once its own recursive parent-creation has already succeeded, so NotFound/AlreadyExists don't apply to the final failure: Err(IoError) if the immediate parent still doesn't exist (recursion didn't take effect), Err(PermissionDenied) otherwise.

remove_dir classifies via exists()-recheck: Err(NotFound) if the path doesn't exist, Err(IoError) for any other reason (including a non-empty directory — ENOTEMPTY isn't separately observable here).

change_dir classifies via exists()-recheck: Err(NotFound) if the path doesn't exist, Err(PermissionDenied) for any other reason.

current_dir returns Err(IoError) if the underlying getcwd() call fails.

list_dir returns Result[[string], error.Error]: builds and returns a FRESH array of directory entry names (skipping "." and ".."), with no out-param and no entry-count cap. Err(NotFound) if the path doesn't exist or isn't a directory, Err(IoError) for any other opendir() failure. Ok(empty array) for an empty directory — distinct from Err.


Functions

fn dir_exists(path: string): bool

Checks if a directory exists at the given path

fn is_directory(path: string): bool

Checks if path is a directory (vs file)

fn parent_dir(path: string): string

Returns the parent directory of path (everything before the last '/'), or "" if there is no meaningful parent to check (e.g. path is a single top-level component like "/foo", whose parent is the root "/", which is assumed to always exist).

fn create_dir_failure_kind(path: string): error.ErrorKind

Classifies a failed create_dir for path: AlreadyExists if the directory is already there, NotFound if its parent directory doesn't exist, PermissionDenied for any other reason.

fn create_dir(path: string): result.Result[bool, error.Error]

Creates a directory with default permissions (0755) Ok(true) on success. See module doc comment for the Err classification.

fn create_dir_all_failure_kind(path: string): error.ErrorKind

Classifies the final failure of create_dir_all for path, once its own recursive parent-creation has already succeeded: IoError if the immediate parent still doesn't exist (the recursion didn't take effect), PermissionDenied otherwise.

fn create_dir_all(path: string): result.Result[bool, error.Error]

Creates a directory and all parent directories (like mkdir -p) Ok(true) on success. See module doc comment for the Err classification.

fn remove_dir_failure_kind(path: string): error.ErrorKind

Classifies a failed remove_dir for path: NotFound if the path doesn't exist, IoError for any other reason (including a non-empty directory — ENOTEMPTY isn't separately observable here).

fn remove_dir(path: string): result.Result[bool, error.Error]

Removes an empty directory Ok(true) on success. See module doc comment for the Err classification.

fn current_dir(): result.Result[string, error.Error]

Returns the current working directory Ok(path) on success. Err(IoError) if the underlying getcwd() call fails.

fn change_dir_failure_kind(path: string): error.ErrorKind

Classifies a failed change_dir for path: NotFound if the path doesn't exist, PermissionDenied for any other reason.

fn change_dir(path: string): result.Result[bool, error.Error]

Changes the current working directory Ok(true) on success. See module doc comment for the Err classification.

fn list_dir_failure_kind(path: string): error.ErrorKind

Classifies a failed opendir() for path: NotFound if the path doesn't exist or isn't a directory, IoError for any other reason (e.g. permission denied).

fn list_dir(path: string): result.Result[[string], error.Error]

Lists directory contents. Builds and returns a FRESH array of entry names, skipping "." and ".." — no out-param, no entry-count cap. Ok(entries) on success (an empty directory yields Ok(empty array), distinct from Err). Err(NotFound) if the path doesn't exist or isn't a directory, Err(IoError) for any other opendir() failure.


Generated by reefc doc