github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/modfetch/cache.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package modfetch 6 7 import ( 8 "github.com/shogo82148/std/context" 9 10 "golang.org/x/mod/module" 11 ) 12 13 func CachePath(ctx context.Context, m module.Version, suffix string) (string, error) 14 15 // DownloadDir returns the directory to which m should have been downloaded. 16 // An error will be returned if the module path or version cannot be escaped. 17 // An error satisfying errors.Is(err, fs.ErrNotExist) will be returned 18 // along with the directory if the directory does not exist or if the directory 19 // is not completely populated. 20 func DownloadDir(ctx context.Context, m module.Version) (string, error) 21 22 // DownloadDirPartialError is returned by DownloadDir if a module directory 23 // exists but was not completely populated. 24 // 25 // DownloadDirPartialError is equivalent to fs.ErrNotExist. 26 type DownloadDirPartialError struct { 27 Dir string 28 Err error 29 } 30 31 func (e *DownloadDirPartialError) Error() string 32 func (e *DownloadDirPartialError) Is(err error) bool 33 34 // SideLock locks a file within the module cache that previously guarded 35 // edits to files outside the cache, such as go.sum and go.mod files in the 36 // user's working directory. 37 // If err is nil, the caller MUST eventually call the unlock function. 38 func SideLock(ctx context.Context) (unlock func(), err error) 39 40 // InfoFile is like Lookup(ctx, path).Stat(version) but also returns the name of the file 41 // containing the cached information. 42 func InfoFile(ctx context.Context, path, version string) (*RevInfo, string, error) 43 44 // GoMod is like Lookup(ctx, path).GoMod(rev) but avoids the 45 // repository path resolution in Lookup if the result is 46 // already cached on local disk. 47 func GoMod(ctx context.Context, path, rev string) ([]byte, error) 48 49 // GoModFile is like GoMod but returns the name of the file containing 50 // the cached information. 51 func GoModFile(ctx context.Context, path, version string) (string, error) 52 53 // GoModSum returns the go.sum entry for the module version's go.mod file. 54 // (That is, it returns the entry listed in go.sum as "path version/go.mod".) 55 func GoModSum(ctx context.Context, path, version string) (string, error)