This section is empty.


This section is empty.


This section is empty.


type Cache

type Cache struct {
	Root string // the root cache directory

    Cache represents an on-disk cache of unpacked tarballs.

    It also knows how to populate and trim it.

    Directory layout:

      <artifact's sha256 hex digest>/
        lock           # lock file to manage concurrent access
        cache.json     # bookkeeping info about this cache entry
        tmp_*.tar.gz   # exists temporarily when fetching the tarball
        tmp_data_*/    # exists temporarily when unpacking the tarball
        data/          # the unpacked tarball goes here

    func (*Cache) Trim

    func (c *Cache) Trim(ctx context.Context, keep int) error

      Trim removes old cache entries, keeping only most recently touched ones.

      func (*Cache) WithTarball

      func (c *Cache) WithTarball(ctx context.Context, src source.Source, cb func(path string) error) error

        WithTarball calls `cb` with a path to the unpacked tarball.

        If the cache has such tarball already (as identified by its SHA256 digest), calls `cb` right away. Otherwise fetches and unpacks the tarball first.

        `cb` may modify files in the directory if necessary. Modification will be preserved in the cache, so `cb` should be careful with them.

        Access to an unpacked tarball directory is protected by a global file system lock. Only one `WithTarball` invocation can touch it concurrently.