@@ -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,7 @@ 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+ func (d * depot ) Track (id strfmt.UUID , deploy * deployment , artifact * buildplan. Artifact ) error {
290296 d .mapMutex .Lock ()
291297 defer d .mapMutex .Unlock ()
292298
@@ -308,6 +314,14 @@ func (d *depot) Track(id strfmt.UUID, deploy *deployment) error {
308314 }
309315 d .config .Cache [id ].InUse = true
310316 d .config .Cache [id ].LastAccessTime = time .Now ().Unix ()
317+
318+ // For dynamically imported artifacts, also include artifact metadata.
319+ if artifact != nil {
320+ d .config .Cache [id ].Namespace = artifact .Ingredients [0 ].Namespace
321+ d .config .Cache [id ].Name = artifact .Name ()
322+ d .config .Cache [id ].Version = artifact .Version ()
323+ }
324+
311325 return nil
312326}
313327
@@ -317,8 +331,8 @@ func (d *depot) Track(id strfmt.UUID, deploy *deployment) error {
317331// This is automatically called by the `Undeploy()` function.
318332// This should be called for ecosystems that handle uninstallation of artifacts.
319333func (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 })
334+ if deployments , ok := d .config .Deployments [id ]; ok {
335+ d .config .Deployments [id ] = sliceutils .Filter (deployments , func (d deployment ) bool { return d .Path != path })
322336 }
323337}
324338
@@ -448,7 +462,7 @@ func (d *depot) Save() error {
448462 for id := range d .artifacts {
449463 if deployments , ok := d .config .Deployments [id ]; ! ok || len (deployments ) == 0 {
450464 if _ , exists := d .config .Cache [id ]; ! exists {
451- err := d .Track (id , nil ) // create cache entry for previously used artifact
465+ err := d .Track (id , nil , nil ) // create cache entry for previously used artifact
452466 if err != nil {
453467 return errs .Wrap (err , "Could not update depot cache with previously used artifact" )
454468 }
0 commit comments