github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/runtime/setup/implementations/alternative/artifact.go (about) 1 package alternative 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/ActiveState/cli/internal/constants" 8 "github.com/ActiveState/cli/internal/errs" 9 "github.com/ActiveState/cli/internal/fileutils" 10 "github.com/ActiveState/cli/internal/multilog" 11 "github.com/ActiveState/cli/internal/unarchiver" 12 "github.com/ActiveState/cli/pkg/platform/runtime/envdef" 13 "github.com/ActiveState/cli/pkg/platform/runtime/store" 14 "github.com/go-openapi/strfmt" 15 ) 16 17 type ArtifactSetup struct { 18 artifactID strfmt.UUID 19 store *store.Store 20 } 21 22 func NewArtifactSetup(artifactID strfmt.UUID, store *store.Store) *ArtifactSetup { 23 return &ArtifactSetup{artifactID, store} 24 } 25 26 func (as *ArtifactSetup) EnvDef(tmpDir string) (*envdef.EnvironmentDefinition, error) { 27 path := filepath.Join(tmpDir, constants.RuntimeDefinitionFilename) 28 e, err := envdef.NewEnvironmentDefinition(path) 29 if err != nil { 30 return nil, errs.Wrap(err, "Could not load environment definitions for artifact.") 31 } 32 33 // Remove the runtime.json file because we don't want it in the installdir 34 if err := os.Remove(path); err != nil { 35 multilog.Error("Could not remove environment definition file: %s", path) 36 } 37 38 return e, nil 39 } 40 41 func (as *ArtifactSetup) Move(tmpDir string) error { 42 return fileutils.MoveAllFilesRecursively(tmpDir, as.store.InstallPath(), func(string, string) {}) 43 } 44 45 func (as *ArtifactSetup) Unarchiver() unarchiver.Unarchiver { 46 return unarchiver.NewTarGz() 47 }