cache

package
v0.0.0-...-cf3f34d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VersionToRevision

func VersionToRevision(version string) string

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides access to the on-disk cache of modules, and the version control repositories that those modules come from. The cache uses locking to ensure that multiple processes may access the same cache simultaneously.

func New

func New(config *Config) *Cache

New creates a cache object to access the cache. The location of the cache is determined by the config. This function does not create, delete or modify any files or directories, it simply opens the cache object for use.

func (*Cache) DownloadRepo

func (cache *Cache) DownloadRepo(modulePath string) (repo *CachedRepo, err error)

DownloadRepo will download the repo corresponding to the given module path, and place it in the repo cache. If that repo is already cached, it won't be downloaded again.

func (*Cache) EnsureDirectoryStructurePresent

func (cache *Cache) EnsureDirectoryStructurePresent() error

EnsureDirectoryStructurePresent will check if the base directories exist on the filesystem, and create them if they do not exist.

func (*Cache) GetModuleBaseDir

func (cache *Cache) GetModuleBaseDir() string

GetModuleBaseDir returns the path of the directory that contains the module cache.

func (*Cache) GetModuleDir

func (cache *Cache) GetModuleDir(version module.Version) (string, error)

GetModuleDir returns the directory where the module (at the given version) should be stored. There is no guarantee that this version of the module is actually in the cache.

func (*Cache) GetReplaceBaseDir

func (cache *Cache) GetReplaceBaseDir() string

GetReplaceBaseDir returns the path of the directory that contains the module replacements cache.

func (*Cache) GetReplaceDir

func (cache *Cache) GetReplaceDir(version module.Version) (string, error)

GetReplaceDir returns the directory where the module (at the given version) should be stored. There is no guarantee that this version of the module is actually in the cache.

func (*Cache) GetRepoBaseDir

func (cache *Cache) GetRepoBaseDir() string

GetRepoBaseDir returns the path of the directory that contains the repository cache.

func (*Cache) GetRepoDir

func (cache *Cache) GetRepoDir(path string) (string, error)

GetRepoDir returns the directory where the repository with the given root path should be stored. There is no guarantee that this repo is actually in the cache.

func (*Cache) InstallMod

func (cache *Cache) InstallMod(version module.Version) (*CachedModule, error)

InstallMod will install the given version of a module into the module cache. If the module is already there, this returns the existing cache entry.

func (*Cache) IsDirectoryStructurePresent

func (cache *Cache) IsDirectoryStructurePresent() (bool, error)

IsDirectoryStructurePresent will check if the base directories exist on the filesystem.

func (*Cache) ListModules

func (cache *Cache) ListModules() ([]module.Version, error)

ListModules will return a slice of every module version that is currently in the cache. If the cache is missing entirely, returns the empty slice.

func (*Cache) RemoveTmpFiles

func (cache *Cache) RemoveTmpFiles() error

RemoveTmpFiles removes any temporary files that were used as part of this cache. This is not the same as clearing the cache, temporary files are used for a single cache instance only.

func (*Cache) ReplaceMod

func (cache *Cache) ReplaceMod(version module.Version, path string) (*CachedModule, error)

ReplaceMod creates a cached replacement directory that mirrors the structure used for remote modules but whose source is the given path.

type CachedModule

type CachedModule struct {
	Dir     *fileutils.LockedDir
	Version module.Version
}

CachedModule represents a module stored in a Cache. This structure contains a lock on the module cache directory. It is essential that you close it!

func (*CachedModule) Close

func (mod *CachedModule) Close() error

func (*CachedModule) GetModFilePath

func (mod *CachedModule) GetModFilePath() string

func (*CachedModule) ListDependencies

func (mod *CachedModule) ListDependencies() ([]module.Version, error)

ListDependencies returns a slice of all this module's direct dependencies We assume that a module lacking a proto.mod file has no dependencies

type CachedRepo

type CachedRepo struct {
	Dir      *fileutils.LockedDir
	RepoRoot *vcs.RepoRoot
}

CachedRepo represents a VCS repo stored in a cache. This structure contains a lock on the repository cache directory. You must close it (use a defer)

func (*CachedRepo) Checkout

func (cr *CachedRepo) Checkout(revision string) error

Checkout will change the contents of the repo to a specified revision. revision could be:

  • a tag name
  • a branch name
  • a commit identifier (e.g. a git commit hash)

This operation is not atomic; if Checkout returns an error, the repo may be in an inconsistent state, so you should call it again before you use the contents of the repo directory for anything.

func (*CachedRepo) CheckoutDefault

func (cr *CachedRepo) CheckoutDefault() error

CheckoutDefault will checkout whatever the remote considers to be the default branch for this repo. e.g. typically 'main' or 'master' for Git repos

func (*CachedRepo) Close

func (cr *CachedRepo) Close() error

func (*CachedRepo) CurrentVersion

func (cr *CachedRepo) CurrentVersion(modulePath string) (module.Version, error)

CurrentVersion calculates the version string used in module files, that corresponds to revision currently checked out in this repository

func (*CachedRepo) FetchUpdates

func (cr *CachedRepo) FetchUpdates() error

FetchUpdates will download new commits from the default remote. This might change the current branch.

func (*CachedRepo) ListTags

func (cr *CachedRepo) ListTags() ([]string, error)

func (*CachedRepo) Update

func (cr *CachedRepo) Update() error

Update will download new commits from the current branch. The tip of the repo should be on a branch for this to work.

type Config

type Config struct {
	// RootDir is the directory under which the cache lives.
	RootDir string `yaml:"root_dir"`
}

func DefaultConfig

func DefaultConfig() *Config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL