Skip to main content

Module fixture

Module fixture 

Source
Expand description

Declarative workspace fixtures: what a level’s directory must look like.

A Fixture lists directories, files, modes and paths to clean. Fixture::apply makes a root match it whatever state the previous attempt left behind, because shellgame reset is the one command that has to work after a player has done something drastic. The repair rules, ported from the Python version:

  • Chmod before delete. Section 8 teaches chmod, so a player can legitimately leave a directory at 000 or a fixture file read-only. Anything that must be replaced or removed is made accessible first.
  • Never follow a symlink. A link at a declared path is removed and replaced; what it pointed to is never read, written, chmod’ed or deleted, and files are created with O_EXCL so not even a race can write through one.
  • File/directory mix-ups are replaced. A directory where a file belongs (or the reverse) is removed and recreated as declared.
  • A fixture cannot target its own root. Cleaning or replacing the root would delete the very directory the level lives in.
  • Directory modes come last, deepest first, so restricting a parent never blocks the chmod of a child.

One deliberate change from the Python version: every directory and file the fixture creates or repairs ends with an explicit mode, 0o755 for directories and 0o644 for files, unless the fixture declares one. Results therefore no longer depend on the player’s umask, and no directory keeps the temporary 0o700 used while repairing. (A kept file, see Fixture::keep_file, is neither created nor repaired, so it keeps whatever mode it has unless one is declared.)

Structs§

Fixture
A declaration of what a directory must contain, built with chained calls.

Enums§

Content
The content of a fixture file: text or raw bytes.
FixtureError
Why a fixture is invalid or could not be applied.

Constants§

DEFAULT_DIR_MODE
Mode of every directory a fixture creates or repairs, unless it declares another.
DEFAULT_FILE_MODE
Mode of every file a fixture writes, unless it declares another.

Functions§

remove_tree
Recursively remove a directory tree (or a single entry), recovering from restricted permissions and never following a symlink. Used by fixtures and by shellgame remove, which must work after the permission levels left directories locked. Missing is fine.