CreateCache creates the cache on the filesystem
()
| 169 | |
| 170 | // CreateCache creates the cache on the filesystem |
| 171 | func (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 | |
| 217 | func (r *Cache) validateCache() error { |
| 218 | r.logger.Debugf("Validating registry cache for %s/%s", r.url.Host, r.url.Path) |