MCPcopy Create free account
hub / github.com/cli/cli / locate

Method locate

script/ghmock/schemafiles.go:65–86  ·  view source on GitHub ↗

locate returns the schema file to use: the file named by the environment variable, a cached copy, or a fresh download into the cache.

(progress io.Writer)

Source from the content-addressed store, hash-verified

63// locate returns the schema file to use: the file named by the environment
64// variable, a cached copy, or a fresh download into the cache.
65func (s schemaSource) locate(progress io.Writer) (string, error) {
66 if p := os.Getenv(s.envVar); p != "" {
67 info, err := os.Stat(p)
68 if err != nil {
69 return "", fmt.Errorf("%s: %w", s.envVar, err)
70 }
71 if info.IsDir() {
72 return "", fmt.Errorf("%s: %s is a directory", s.envVar, p)
73 }
74 return p, nil
75 }
76 p, err := s.cachePath()
77 if err != nil {
78 return "", err
79 }
80 if _, err := os.Stat(p); err == nil {
81 return p, nil
82 } else if !errors.Is(err, fs.ErrNotExist) {
83 return "", err
84 }
85 return p, s.download(p, progress)
86}
87
88func (s schemaSource) cachePath() (string, error) {
89 dir, err := schemaCacheDir()

Callers 3

TestSchemaSourceLocateFunction · 0.80
graphQLMethod · 0.80
restMethod · 0.80

Calls 4

cachePathMethod · 0.95
downloadMethod · 0.95
IsDirMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestSchemaSourceLocateFunction · 0.64