func cacheDir(ctx context.Context, path string) (string, error) { … } func CachePath(ctx context.Context, m module.Version, suffix string) (string, error) { … } // DownloadDir returns the directory to which m should have been downloaded. // An error will be returned if the module path or version cannot be escaped. // An error satisfying errors.Is(err, fs.ErrNotExist) will be returned // along with the directory if the directory does not exist or if the directory // is not completely populated. func DownloadDir(ctx context.Context, m module.Version) (string, error) { … } type DownloadDirPartialError … func (e *DownloadDirPartialError) Error() string { … } func (e *DownloadDirPartialError) Is(err error) bool { … } // lockVersion locks a file within the module cache that guards the downloading // and extraction of the zipfile for the given module version. func lockVersion(ctx context.Context, mod module.Version) (unlock func(), err error) { … } // SideLock locks a file within the module cache that previously guarded // edits to files outside the cache, such as go.sum and go.mod files in the // user's working directory. // If err is nil, the caller MUST eventually call the unlock function. func SideLock(ctx context.Context) (unlock func(), err error) { … } type cachingRepo … func newCachingRepo(ctx context.Context, path string, initRepo func(context.Context) (Repo, error)) *cachingRepo { … } func (r *cachingRepo) repo(ctx context.Context) Repo { … } func (r *cachingRepo) CheckReuse(ctx context.Context, old *codehost.Origin) error { … } func (r *cachingRepo) ModulePath() string { … } func (r *cachingRepo) Versions(ctx context.Context, prefix string) (*Versions, error) { … } type cachedInfo … func (r *cachingRepo) Stat(ctx context.Context, rev string) (*RevInfo, error) { … } func (r *cachingRepo) Latest(ctx context.Context) (*RevInfo, error) { … } func (r *cachingRepo) GoMod(ctx context.Context, version string) ([]byte, error) { … } func (r *cachingRepo) Zip(ctx context.Context, dst io.Writer, version string) error { … } // InfoFile is like Lookup(ctx, path).Stat(version) but also returns the name of the file // containing the cached information. func InfoFile(ctx context.Context, path, version string) (*RevInfo, string, error) { … } // GoMod is like Lookup(ctx, path).GoMod(rev) but avoids the // repository path resolution in Lookup if the result is // already cached on local disk. func GoMod(ctx context.Context, path, rev string) ([]byte, error) { … } // GoModFile is like GoMod but returns the name of the file containing // the cached information. func GoModFile(ctx context.Context, path, version string) (string, error) { … } // GoModSum returns the go.sum entry for the module version's go.mod file. // (That is, it returns the entry listed in go.sum as "path version/go.mod".) func GoModSum(ctx context.Context, path, version string) (string, error) { … } var errNotCached … // readDiskStat reads a cached stat result from disk, // returning the name of the cache file and the result. // If the read fails, the caller can use // writeDiskStat(file, info) to write a new cache entry. func readDiskStat(ctx context.Context, path, rev string) (file string, info *RevInfo, err error) { … } // readDiskStatByHash is a fallback for readDiskStat for the case // where rev is a commit hash instead of a proper semantic version. // In that case, we look for a cached pseudo-version that matches // the commit hash. If we find one, we use it. // This matters most for converting legacy package management // configs, when we are often looking up commits by full hash. // Without this check we'd be doing network I/O to the remote repo // just to find out about a commit we already know about // (and have cached under its pseudo-version). func readDiskStatByHash(ctx context.Context, path, rev string) (file string, info *RevInfo, err error) { … } var oldVgoPrefix … // readDiskGoMod reads a cached go.mod file from disk, // returning the name of the cache file and the result. // If the read fails, the caller can use // writeDiskGoMod(file, data) to write a new cache entry. func readDiskGoMod(ctx context.Context, path, rev string) (file string, data []byte, err error) { … } // readDiskCache is the generic "read from a cache file" implementation. // It takes the revision and an identifying suffix for the kind of data being cached. // It returns the name of the cache file and the content of the file. // If the read fails, the caller can use // writeDiskCache(file, data) to write a new cache entry. func readDiskCache(ctx context.Context, path, rev, suffix string) (file string, data []byte, err error) { … } // writeDiskStat writes a stat result cache entry. // The file name must have been returned by a previous call to readDiskStat. func writeDiskStat(ctx context.Context, file string, info *RevInfo) error { … } // writeDiskGoMod writes a go.mod cache entry. // The file name must have been returned by a previous call to readDiskGoMod. func writeDiskGoMod(ctx context.Context, file string, text []byte) error { … } // writeDiskCache is the generic "write to a cache file" implementation. // The file must have been returned by a previous call to readDiskCache. func writeDiskCache(ctx context.Context, file string, data []byte) error { … } // tempFile creates a new temporary file with given permission bits. func tempFile(ctx context.Context, dir, prefix string, perm fs.FileMode) (f *os.File, err error) { … } // rewriteVersionList rewrites the version list in dir // after a new *.mod file has been written. func rewriteVersionList(ctx context.Context, dir string) (err error) { … } var statCacheOnce … var statCacheErr … var counterErrorsGOMODCACHEEntryRelative … // checkCacheDir checks if the directory specified by GOMODCACHE exists. An // error is returned if it does not. func checkCacheDir(ctx context.Context) error { … }