Skip to main content

Module scratch

Module scratch 

Source
Expand description

Scratch folders: the rule every Rust test in the workspace keeps for what it writes outside its own memory. Its scratch is removed whatever happens: when it passes, fails or panics, and when a child it runs ends, aborts, overflows its stack or is killed. (Review round 9: a stack probe’s folder, made in a child its bisection overflows by design, outlived every such child; a test whose own process a mutant aborted left a chain of 996 folders; two tests removed their files only after their asserts.)

  • Every scratch folder is a Scratch, removed with what it holds when dropped, which a panic’s unwinding does too. No test names std::env::temp_dir but this module (direct_scratch scans for it).
  • A child’s scratch is its parent’s. crate::child::output and crate::child::status make a folder for each run of a child, name it in the child’s VAR, and remove it when the run ends, however it ends. A child that makes a Scratch (this test binary run again as a probe, or a Python test through tools/parity/scratch.py, which keeps the same rule) makes it inside that folder. A child that aborts or is killed runs no drop of its own, so its parent’s removal is the one that runs.
  • A process with no parent’s folder makes its folders in a root of its own in the temp folder, unityrs-test-<pid namespace>-<pid>, which goes with the last of them. A process that dies in its own code (an abort, a stack overflow, a kill) leaves its root behind, so the first folder any process makes removes every such root whose process no longer runs (sweep): a root is its own process’s alone, and only roots of this pid namespace are compared with its processes.

Owner: package B.

Structs§

Scratch
A new empty folder, removed with everything in it when dropped (module docs).

Constants§

PREFIX
The name of every process’s own root, before its pid namespace and pid.
VAR
The variable naming the folder a parent made for its child to make its scratch in (module docs).

Functions§

direct_scratch
Every place under root (its .rs files, target directories left out, this file too) that names the temp folder other than through this module: each line outside a // comment that names temp_dir().
remove_tree
Removes path and everything under it a folder at a time, without following a link: a chain of folders past the stack or the open-file limit, and a folder of mode 000, go too. Nothing when it is not there.
sweep
Removes every root in the temp folder of a process of this pid namespace that no longer runs (module docs). Nothing on a system without /proc’s pid namespaces.