Skip to main content

Module path

Module path 

Source
Expand description

Path sanitization utilities.

Provides sanitize_for_fs() which transforms an arbitrary string into a filesystem-safe identifier using a djb2 hash and radix-36 encoding. Used for session directories, worktree slugs, and any other case where an untrusted string must become a safe directory or file name.

Constants§

MAX_LINK_HOPS
How many symbolic links a resolution follows before it takes a loop for one, as the OS does (SYMLOOP_MAX).
MAX_SANITIZED_LENGTH
Public constant for external crates (e.g. agix-history tests) that need to verify sanitized output length bounds.

Functions§

first_below
When rest starts with a name: that name under the resolved out — a link the OS could not resolve, if it is one — and the rest after it.
normalize_lexically
p with . dropped and each .. taking off the component before it, without touching the filesystem, so it does not know a .. after a symlink climbs out of the link’s target (resolve_physically does).
put_back
rest put onto the resolved out lexically.
resolve_physically
Where path lands on this machine’s disk: its deepest prefix that exists, resolved by the OS, with the rest put back on lexically. The rest does not exist, so it holds no symlink a lexical .. could misjudge — except its first name, a link the OS cannot resolve because what it points at does not exist yet, which a write follows and so is followed here.
sanitize_for_fs
Sanitize a string for use as a filesystem component (file name or directory).