Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ please use "--purge".`,
err = errs.ErrPackNotInstalled
}
} else {
err = installer.RemovePack(packPath, rmCmdFlags.purge, false, viper.GetInt("timeout"))
_, err = installer.RemovePack(packPath, rmCmdFlags.purge, false)
}
if err != nil {
if err != errs.ErrAlreadyLogged {
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Update a pack using the following "<pack>" specification or using packs provided
return nil // nothing to do
}
installer.UnlockPackRoot()
err := installer.UpdatePack("", !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, viper.GetInt("timeout"))
err := installer.UpdatePack("", !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, false, viper.GetInt("timeout"))
if err != nil {
lastErr = err
if !errs.AlreadyLogged(err) {
Expand All @@ -105,7 +105,7 @@ Update a pack using the following "<pack>" specification or using packs provided
log.Debugf("Specified packs %v", args)
installer.UnlockPackRoot()
for _, packPath := range args {
err := installer.UpdatePack(packPath, !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, viper.GetInt("timeout"))
err := installer.UpdatePack(packPath, !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, false, viper.GetInt("timeout"))
if err != nil {
lastErr = err
if !errs.AlreadyLogged(err) {
Expand Down
1 change: 0 additions & 1 deletion cmd/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var (
// Errors related to package content
ErrPdscFileNotFound = errors.New("pdsc not found")
ErrPackNotInstalled = errors.New("pack not installed")
ErrPackNotPurgeable = errors.New("pack not purgeable")
ErrPdscEntryExists = errors.New("pdsc already in index")
ErrPdscEntryNotFound = errors.New("pdsc not found in index")
ErrEula = errors.New("user does not agree with the pack's license")
Expand Down
41 changes: 22 additions & 19 deletions cmd/installer/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ func isGlobal(packPath string) (bool, error) {
// - toBeRemoved: A boolean indicating if the pack is to be removed.
// - forceLatest: A boolean indicating if the latest version of the pack should be used.
// - noLocal: A boolean indicating if local installations should be ignored.
// - timeout: An integer specifying the timeout duration for network operations.
//
// Returns:
// - *PackType: A pointer to the prepared PackType object.
// - error: An error if any issues occur during preparation.
func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool, timeout int) (*PackType, error) {
func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool) (*PackType, error) {
pack := &PackType{
path: packPath,
toBeRemoved: toBeRemoved,
Expand Down Expand Up @@ -158,10 +157,7 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
}

if pdscTag.URL != "" {
err = Installation.downloadPdscFile(pdscTag, false, timeout)
if err != nil {
return pack, err
}
pack.URL = pdscTag.URL
}

pack.isInstalled, pack.installedVersions = Installation.PackIsInstalled(pack, noLocal)
Expand All @@ -172,8 +168,6 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
if pdscTag.Name != "" {
pack.Name = pdscTag.Name
}
// pack.Version = pdscTag.Version
// pack.URL = pdscTag.URL

return pack, nil
}
Expand Down Expand Up @@ -276,11 +270,19 @@ func (p *PackType) validate() error {
return errs.ErrPdscFileNotFound
}

// purge Removes cached files when
// - It
// - Removes "CMSIS_PACK_ROOT/.Download/p.Vendor.p.Name.p.Version.pdsc"
// - Removes "CMSIS_PACK_ROOT/.Download/p.Vendor.p.Name.p.Version.pack" (or zip)
func (p *PackType) purge() error {
// purge removes all cached files matching the pattern derived from the PackType's
// Vendor, Name, and Version fields from the download directory. The pattern
// matches files with extensions `.pack`, `.zip`, or `.pdsc`.
//
// It logs the purging process, including the files to be removed. If no files
// match the pattern, it logs that the pack version is already removed and
// returns true with no error.
//
// Returns:
// - A boolean indicating whether the pack version was already removed (true)
// or not (false).
// - An error if any issue occurs during the file listing or removal process.
func (p *PackType) purge() (bool, error) {
log.Debugf("Purging \"%v\"", p.path)

fileNamePattern := p.Vendor + "\\." + p.Name
Expand All @@ -293,21 +295,22 @@ func (p *PackType) purge() error {

files, err := utils.ListDir(Installation.DownloadDir, fileNamePattern)
if err != nil {
return err
return false, err
}

log.Debugf("Files to be purged \"%v\"", files)
if len(files) == 0 {
return errs.ErrPackNotPurgeable
log.Infof("pack %s.%s already removed from %s", p.path, p.Version, Installation.DownloadDir)
return true, nil
}

for _, file := range files {
if err := os.Remove(file); err != nil {
return err
return false, err
}
}

return nil
return false, nil
}

// install installs pack files to installation's directories
Expand Down Expand Up @@ -666,12 +669,12 @@ func (p *PackType) loadDependencies(nometa bool) error {
var pack *PackType
var err error
if version == "" {
pack, err = preparePack(deps[i][1]+"."+deps[i][0], false, false, false, nometa, 0)
pack, err = preparePack(deps[i][1]+"."+deps[i][0], false, false, false, nometa)
if err != nil {
return err
}
} else {
pack, err = preparePack(deps[i][1]+"."+deps[i][0]+"."+deps[i][2], false, false, false, nometa, 0)
pack, err = preparePack(deps[i][1]+"."+deps[i][0]+"."+deps[i][2], false, false, false, nometa)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/pdsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (p *PdscType) install(installation *PacksInstallationType) error {
}
}

return Installation.LocalPidx.AddPdsc(tag)
return installation.LocalPidx.AddPdsc(tag)
}

// uninstall uninstalls a pack via PDSC
Expand Down
Loading
Loading