@@ -21,6 +21,7 @@ import (
2121 configMediator "github.com/ActiveState/cli/internal/mediators/config"
2222 "github.com/ActiveState/cli/internal/sliceutils"
2323 "github.com/ActiveState/cli/internal/smartlink"
24+ "github.com/ActiveState/cli/pkg/buildplan"
2425)
2526
2627const (
@@ -52,6 +53,11 @@ type artifactInfo struct {
5253 Size int64 `json:"size"`
5354 LastAccessTime int64 `json:"lastAccessTime"`
5455
56+ // These fields are used by ecosystems during Add/Remove/Apply.
57+ Namespace string `json:"namespace,omitempty"`
58+ Name string `json:"name,omitempty"`
59+ Version string `json:"version,omitempty"`
60+
5561 id strfmt.UUID // for convenience when removing stale artifacts; should NOT have json tag
5662}
5763
@@ -218,7 +224,7 @@ func (d *depot) DeployViaLink(id strfmt.UUID, relativeSrc, absoluteDest string)
218224 Path : absoluteDest ,
219225 Files : files .RelativePaths (),
220226 RelativeSrc : relativeSrc ,
221- })
227+ }, nil )
222228 if err != nil {
223229 return errs .Wrap (err , "Could not record artifact use" )
224230 }
@@ -275,7 +281,7 @@ func (d *depot) DeployViaCopy(id strfmt.UUID, relativeSrc, absoluteDest string)
275281 Path : absoluteDest ,
276282 Files : files .RelativePaths (),
277283 RelativeSrc : relativeSrc ,
278- })
284+ }, nil )
279285 if err != nil {
280286 return errs .Wrap (err , "Could not record artifact use" )
281287 }
@@ -286,7 +292,9 @@ func (d *depot) DeployViaCopy(id strfmt.UUID, relativeSrc, absoluteDest string)
286292// Track will record an artifact deployment.
287293// This is automatically called by `DeployVia*()` functions.
288294// This should be called for ecosystems that handle installation of artifacts.
289- func (d * depot ) Track (id strfmt.UUID , deploy * deployment ) error {
295+ // The artifact parameter is only necessary for tracking dynamically imported artifacts after being
296+ // added by an ecosystem.
297+ func (d * depot ) Track (id strfmt.UUID , deploy * deployment , artifact * buildplan.Artifact ) error {
290298 d .mapMutex .Lock ()
291299 defer d .mapMutex .Unlock ()
292300
@@ -308,6 +316,14 @@ func (d *depot) Track(id strfmt.UUID, deploy *deployment) error {
308316 }
309317 d .config .Cache [id ].InUse = true
310318 d .config .Cache [id ].LastAccessTime = time .Now ().Unix ()
319+
320+ // For dynamically imported artifacts, also include artifact metadata.
321+ if artifact != nil {
322+ d .config .Cache [id ].Namespace = artifact .Ingredients [0 ].Namespace
323+ d .config .Cache [id ].Name = artifact .Name ()
324+ d .config .Cache [id ].Version = artifact .Version ()
325+ }
326+
311327 return nil
312328}
313329
@@ -317,8 +333,8 @@ func (d *depot) Track(id strfmt.UUID, deploy *deployment) error {
317333// This is automatically called by the `Undeploy()` function.
318334// This should be called for ecosystems that handle uninstallation of artifacts.
319335func (d * depot ) Untrack (id strfmt.UUID , path string ) {
320- if _ , ok := d .config .Deployments [id ]; ok {
321- d .config .Deployments [id ] = sliceutils .Filter (d . config . Deployments [ id ] , func (d deployment ) bool { return d .Path != path })
336+ if deployments , ok := d .config .Deployments [id ]; ok {
337+ d .config .Deployments [id ] = sliceutils .Filter (deployments , func (d deployment ) bool { return d .Path != path })
322338 }
323339}
324340
@@ -445,7 +461,7 @@ func (d *depot) Save() error {
445461 for id := range d .artifacts {
446462 if deployments , ok := d .config .Deployments [id ]; ! ok || len (deployments ) == 0 {
447463 if _ , exists := d .config .Cache [id ]; ! exists {
448- err := d .Track (id , nil ) // create cache entry for previously used artifact
464+ err := d .Track (id , nil , nil ) // create cache entry for previously used artifact
449465 if err != nil {
450466 return errs .Wrap (err , "Could not update depot cache with previously used artifact" )
451467 }
0 commit comments