Skip to main content

Module paths

Module paths 

Source
Expand description

Section-relative paths and containment: the one implementation.

Level authors declare paths, not locations. A fixture, a requirement, a start directory and a cd rule all speak the same vocabulary, and all of them go through this module, so a level can never disagree with itself about where it lives, nor reach outside the workspace the game owns by way of .., an absolute path or a symlinked parent.

Two different jobs live here:

  • Declared paths (RelPath, resolve_within): strict. Anything that is not a plain relative path, or that passes through a symlink, is rejected.
  • Observed paths (normalize_lexically, soft_canonicalize): lenient. They describe where the player is or is going, which may not exist yet, and they never fail.

Structs§

RelPath
A declared path that is relative to a section root and cannot leave it.

Enums§

ContainmentError
A declared path does not stay inside the root it is resolved against.
PathError
Why a declared path was refused as a plain relative path.

Functions§

normalize_lexically
Resolve . and .. textually, the way cd -L does for the logical $PWD.
resolve_within
Resolve a declared path against root, refusing to escape it.
same_path
True when two paths name the same location: both are soft-canonicalized first, so a path through a symlinked ancestor (macOS /tmp) equals its canonical spelling and a directory that does not exist yet can still be compared.
soft_canonicalize
Canonicalize the longest existing prefix of path and append the rest.