MCPcopy Create free account
hub / github.com/buildpacks/pack / CreateCache

Method CreateCache

internal/registry/registry_cache.go:171–215  ·  view source on GitHub ↗

CreateCache creates the cache on the filesystem

()

Source from the content-addressed store, hash-verified

169
170// CreateCache creates the cache on the filesystem
171func (r *Cache) CreateCache() error {
172 var repository *git.Repository
173 r.logger.Debugf("Creating registry cache for %s/%s", r.url.Host, r.url.Path)
174
175 registryDir, err := os.MkdirTemp(filepath.Dir(r.Root), "registry")
176 if err != nil {
177 return err
178 }
179
180 r.RegistryDir = registryDir
181
182 if r.url.Host == "dev.azure.com" {
183 err = exec.Command("git", "clone", r.url.String(), r.RegistryDir).Run()
184 if err != nil {
185 return errors.Wrap(err, "cloning remote registry with native git")
186 }
187
188 repository, err = git.PlainOpen(r.RegistryDir)
189 if err != nil {
190 return errors.Wrap(err, "opening remote registry clone")
191 }
192 } else {
193 repository, err = git.PlainClone(r.RegistryDir, false, &git.CloneOptions{
194 URL: r.url.String(),
195 })
196 if err != nil {
197 return errors.Wrap(err, "cloning remote registry")
198 }
199 }
200
201 w, err := repository.Worktree()
202 if err != nil {
203 return err
204 }
205
206 err = os.Rename(w.Filesystem.Root(), r.Root)
207 if err != nil {
208 if err == os.ErrExist {
209 // If pack is run concurrently, this action might have already occurred
210 return nil
211 }
212 return err
213 }
214 return nil
215}
216
217func (r *Cache) validateCache() error {
218 r.logger.Debugf("Validating registry cache for %s/%s", r.url.Host, r.url.Path)

Callers 2

InitializeMethod · 0.95
testRegistryCacheFunction · 0.80

Calls 3

DebugfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.45

Tested by 1

testRegistryCacheFunction · 0.64