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§
- Open
Options - Options to open a file with async path-traversal protection.
- Open
Options Sync - Options to open a file with blocking path-traversal protection.
Enums§
- Created
File Permissions - Permissions to apply when
OpenOptionsorOpenOptionsSynccreates a new file. - Symlink
Policy - How symbolic links are treated when opening a file confined to a root
directory via
OpenOptions::jailorOpenOptionsSync::jail. - Unsafe
Path Error - Error returned when a path is rejected as unsafe.
Functions§
- is_
reserved_ device_ name - Whether
namematches 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
pathread-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
pathbelowrootafter applying root-confined path validation. - safe_
path_ in_ sync - Blocking variant of
safe_path_in. - safe_
write_ in - Write
contentsto a file belowroot, creating missing parent directories. - safe_
write_ in_ sync - Blocking variant of
safe_write_in. - sanitize_
path - Validate
pathand return a cleaned, lexically-equivalent path that is safe from “dot-dot” traversal. - sanitize_
relative_ path - Like
sanitize_pathbut additionally requires the path to be relative, rejecting absolute paths and drive/UNC prefixes (UnsafePathError::Absolute).