Skip to main content

Module fs

Module fs 

Available on crate feature std only.
Expand description

Filesystem helpers shared by Rama crates.

Async helpers are the default. Use the _sync variants from blocking code.

These helpers are implemented with std/tokio path APIs. They reject lexical traversal and static symlink escapes, but they cannot make path-based checks race-free if an attacker can concurrently mutate the checked directory. Use them with roots that are not writable by untrusted actors.

Structs§

OpenOptions
Options to open a file with async path-traversal protection.
OpenOptionsSync
Options to open a file with blocking path-traversal protection.

Enums§

CreatedFilePermissions
Permissions to apply when OpenOptions or OpenOptionsSync creates a new file.
SymlinkPolicy
How symbolic links are treated when opening a file confined to a root directory via OpenOptions::jail or OpenOptionsSync::jail.
UnsafePathError
Error returned when a path is rejected as unsafe.

Functions§

is_reserved_device_name
Whether name matches a reserved Windows device name (e.g. CON, NUL, COM1, LPT9), independent of the current platform.
safe_create_dir_all_in
Create a directory and all missing parents below root.
safe_create_dir_all_in_sync
Blocking variant of safe_create_dir_all_in.
safe_open
Open path read-only with path-traversal protection.
safe_open_in
Open a file read-only, confined to within the trusted directory root.
safe_open_in_sync
Blocking variant of safe_open_in.
safe_open_sync
Blocking variant of safe_open.
safe_path_in
Resolve path below root after applying root-confined path validation.
safe_path_in_sync
Blocking variant of safe_path_in.
safe_write_in
Write contents to a file below root, creating missing parent directories.
safe_write_in_sync
Blocking variant of safe_write_in.
sanitize_path
Validate path and return a cleaned, lexically-equivalent path that is safe from “dot-dot” traversal.
sanitize_relative_path
Like sanitize_path but additionally requires the path to be relative, rejecting absolute paths and drive/UNC prefixes (UnsafePathError::Absolute).