Sys.Tmp (Hyper v0.1.0)

Copy Markdown View Source

Temporary file/directory helpers.

Names carry the caller's prefix (so leaked entries are identifiable) plus a cryptographically random component, and creation is exclusive (O_EXCL / plain mkdir) with retry-on-collision — so concurrent callers, other OS processes, VM restarts, and pre-planted paths (symlinks in a world-writable tmp dir) can never hand a caller a path someone else controls.

Summary

Functions

Create a fresh temporary directory, pass its path to fun, and remove it (recursively) afterward - even if fun raises. Returns whatever fun returns.

Create a fresh empty temporary file, pass its path to fun, and remove it afterward - even if fun raises. Returns whatever fun returns.

Functions

with_tempdir(prefix \\ "hyper", fun)

@spec with_tempdir(String.t(), (Path.t() -> result)) :: result when result: var

Create a fresh temporary directory, pass its path to fun, and remove it (recursively) afterward - even if fun raises. Returns whatever fun returns.

with_tmpfile(prefix \\ "hyper", fun)

@spec with_tmpfile(String.t(), (Path.t() -> result)) :: result when result: var

Create a fresh empty temporary file, pass its path to fun, and remove it afterward - even if fun raises. Returns whatever fun returns.