# `NBPR.Artifact.Cache`
[🔗](https://github.com/jimsynz/nbpr/blob/v0.7.0/lib/nbpr/artifact/cache.ex#L1)

On-disk cache for NBPR package artefacts.

Pure path/key logic lives in `NBPR.Artifact`; this module owns the I/O —
checking whether an artefact is already extracted, and atomically extracting
a downloaded tarball into the cache directory.

Extraction goes via a sibling temp directory and then a rename, so a failed
extract never leaves a half-populated cache directory behind.

# `entry`

```elixir
@type entry() :: %{
  dir: String.t(),
  path: String.t(),
  manifest: map() | nil,
  mtime: integer()
}
```

# `extract!`

```elixir
@spec extract!(Path.t(), NBPR.Artifact.build_inputs()) :: :ok
```

Extracts a downloaded tarball into the canonical cache directory for the
given inputs.

The tarball is expected to contain exactly one top-level directory (matching
Nerves' `--strip-components=1` convention); the contents of that directory
become the cache directory's contents. Extraction is atomic via a temp
directory + rename.

# `list`

```elixir
@spec list() :: [entry()]
```

Lists extracted artefacts in the cache root.

An entry is a cache-root subdirectory containing a `manifest.json` — this
skips siblings like `dl/` (staged downloads) and `system-source/`. Each
entry carries its directory name, absolute path, parsed manifest (or `nil`
if the JSON is unreadable), and POSIX mtime. Sorted newest-first.

# `remove!`

```elixir
@spec remove!(Path.t()) :: :ok
```

Removes a single cache entry by absolute path. Returns `:ok`.

# `valid?`

```elixir
@spec valid?(NBPR.Artifact.build_inputs()) :: boolean()
```

Returns `true` when the artefact is already extracted into the cache
directory. Currently a presence check; manifest-based verification is added
alongside the resolver in a later commit.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
