Skip to content

Commit 99c5bbb

Browse files
committed
Use public methods for depot access.
1 parent 84ffb1e commit 99c5bbb

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

pkg/runtime/depot.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,15 @@ func (d *depot) SetCacheSize(mb int) {
154154
d.cacheSize = int64(mb) * MB
155155
}
156156

157-
func (d *depot) Exists(id strfmt.UUID) bool {
158-
_, ok := d.artifacts[id]
159-
return ok
157+
// Note: the returned artifactInfo may be nil for depot artifacts that predate this functionality.
158+
func (d *depot) Exists(id strfmt.UUID) (bool, *artifactInfo) {
159+
if _, ok := d.artifacts[id]; ok {
160+
if artifact, exists := d.config.Cache[id]; exists {
161+
return true, artifact
162+
}
163+
return true, nil
164+
}
165+
return false, nil
160166
}
161167

162168
func (d *depot) Path(id strfmt.UUID) string {
@@ -184,7 +190,7 @@ func (d *depot) DeployViaLink(id strfmt.UUID, relativeSrc, absoluteDest string)
184190
d.fsMutex.Lock()
185191
defer d.fsMutex.Unlock()
186192

187-
if !d.Exists(id) {
193+
if exists, _ := d.Exists(id); !exists {
188194
return errs.New("artifact not found in depot")
189195
}
190196

@@ -237,7 +243,7 @@ func (d *depot) DeployViaCopy(id strfmt.UUID, relativeSrc, absoluteDest string)
237243
d.fsMutex.Lock()
238244
defer d.fsMutex.Unlock()
239245

240-
if !d.Exists(id) {
246+
if exists, _ := d.Exists(id); !exists {
241247
return errs.New("artifact not found in depot")
242248
}
243249

@@ -327,6 +333,13 @@ func (d *depot) Track(id strfmt.UUID, deploy *deployment, artifact *buildplan.Ar
327333
return nil
328334
}
329335

336+
func (d *depot) Deployments(id strfmt.UUID) []deployment {
337+
if deployments, ok := d.config.Deployments[id]; ok {
338+
return deployments
339+
}
340+
return nil
341+
}
342+
330343
// Untrack will remove an artifact deployment.
331344
// It does not actually delete files; it just tells the depot a previously tracked artifact should
332345
// no longer be tracked.
@@ -342,7 +355,7 @@ func (d *depot) Undeploy(id strfmt.UUID, relativeSrc, path string) error {
342355
d.fsMutex.Lock()
343356
defer d.fsMutex.Unlock()
344357

345-
if !d.Exists(id) {
358+
if exists, _ := d.Exists(id); !exists {
346359
return errs.New("artifact not found in depot")
347360
}
348361

pkg/runtime/setup.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ func newSetup(path string, bp *buildplan.BuildPlan, env *envdef.Collection, depo
139139
// by definition we'll need to download it (unless we're setting up the runtime from an archive).
140140
// We also calculate which artifacts are immediately ready to be installed, as its the inverse condition of the above.
141141
artifactsToDownload := artifactsToInstall.Filter(func(a *buildplan.Artifact) bool {
142-
return !depot.Exists(a.ArtifactID)
142+
exists, _ := depot.Exists(a.ArtifactID)
143+
return !exists
143144
})
144145
artifactsToUnpack := artifactsToDownload
145146
if opts.FromArchive != nil {
@@ -545,15 +546,13 @@ func (s *setup) uninstall(id strfmt.UUID) (rerr error) {
545546
}
546547

547548
// If this is a dynamically imported artifact, tell the ecosystem to remove/undeploy it.
548-
if artifact, exists := s.depot.config.Cache[id]; exists && artifact.Namespace != "" {
549+
if exists, artifact := s.depot.Exists(id); exists && artifact != nil && artifact.Namespace != "" {
549550
if ecosys := filterEcosystemMatchingNamespace(s.ecosystems, artifact.Namespace); ecosys != nil {
550551
installedFiles := []string{}
551552
// Find record of our deployment
552-
if deployments, ok := s.depot.config.Deployments[id]; ok {
553-
deployments = sliceutils.Filter(deployments, func(d deployment) bool { return d.Path == s.path })
554-
if len(deployments) > 0 {
555-
installedFiles = deployments[0].Files
556-
}
553+
deployments := sliceutils.Filter(s.depot.Deployments(id), func(d deployment) bool { return d.Path == s.path })
554+
if len(deployments) > 0 {
555+
installedFiles = deployments[0].Files
557556
}
558557

559558
// Convert relative install locations to absolute paths.

0 commit comments

Comments
 (0)