github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/runtime/setup/implementations/camel/runtime.go (about)

     1  package camel
     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/locale"
    10  	"github.com/ActiveState/cli/pkg/buildplan"
    11  	"github.com/ActiveState/cli/pkg/platform/runtime/store"
    12  	"github.com/go-openapi/strfmt"
    13  )
    14  
    15  type Setup struct {
    16  	store *store.Store
    17  }
    18  
    19  func NewSetup(s *store.Store) *Setup {
    20  	return &Setup{s}
    21  }
    22  
    23  // DeleteOutdatedArtifacts deletes the entire installation directory, unless alreadyInstalled is not zero, which can happen when the executors directory needs to be re-generated.
    24  func (s *Setup) DeleteOutdatedArtifacts(_ *buildplan.ArtifactChangeset, _, alreadyInstalled store.StoredArtifactMap) error {
    25  	if len(alreadyInstalled) != 0 {
    26  		return nil
    27  	}
    28  	files, err := os.ReadDir(s.store.InstallPath())
    29  	if err != nil {
    30  		return errs.Wrap(err, "Error reading previous camel installation")
    31  	}
    32  	for _, file := range files {
    33  		if file.Name() == constants.LocalRuntimeTempDirectory || file.Name() == constants.LocalRuntimeEnvironmentDirectory {
    34  			continue // do not delete files that do not belong to previous installation
    35  		}
    36  		err = os.RemoveAll(filepath.Join(s.store.InstallPath(), file.Name()))
    37  		if err != nil {
    38  			return errs.Wrap(err, "Error removing previous camel installation")
    39  		}
    40  	}
    41  	return nil
    42  }
    43  
    44  func (s *Setup) ResolveArtifactName(_ strfmt.UUID) string {
    45  	return locale.Tl("camel_bundle_name", "bundle")
    46  }