Skip to content

Commit 959ed79

Browse files
authored
replaced PDSC checks by PIDX for update (#505)
## Fixes - ## Changes - ## Checklist <!-- Put an `x` in the boxes. All tasks must be completed and boxes checked before merging. --> - [x] 🤖 This change is covered by unit tests (if applicable). - [x] 🤹 Manual testing has been performed (if necessary). - [x] 🛡️ Security impacts have been considered (if relevant). - [x] 📖 Documentation updates are complete (if required). - [x] 🧠 Third-party dependencies and TPIP updated (if required).
1 parent 36a472e commit 959ed79

File tree

11 files changed

+179
-98
lines changed

11 files changed

+179
-98
lines changed

cmd/commands/rm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ please use "--purge".`,
6666
err = errs.ErrPackNotInstalled
6767
}
6868
} else {
69-
err = installer.RemovePack(packPath, rmCmdFlags.purge, false, viper.GetInt("timeout"))
69+
_, err = installer.RemovePack(packPath, rmCmdFlags.purge, false)
7070
}
7171
if err != nil {
7272
if err != errs.ErrAlreadyLogged {

cmd/commands/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Update a pack using the following "<pack>" specification or using packs provided
9191
return nil // nothing to do
9292
}
9393
installer.UnlockPackRoot()
94-
err := installer.UpdatePack("", !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, viper.GetInt("timeout"))
94+
err := installer.UpdatePack("", !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, false, viper.GetInt("timeout"))
9595
if err != nil {
9696
lastErr = err
9797
if !errs.AlreadyLogged(err) {
@@ -105,7 +105,7 @@ Update a pack using the following "<pack>" specification or using packs provided
105105
log.Debugf("Specified packs %v", args)
106106
installer.UnlockPackRoot()
107107
for _, packPath := range args {
108-
err := installer.UpdatePack(packPath, !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, viper.GetInt("timeout"))
108+
err := installer.UpdatePack(packPath, !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, false, viper.GetInt("timeout"))
109109
if err != nil {
110110
lastErr = err
111111
if !errs.AlreadyLogged(err) {

cmd/errors/errors.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var (
3434
// Errors related to package content
3535
ErrPdscFileNotFound = errors.New("pdsc not found")
3636
ErrPackNotInstalled = errors.New("pack not installed")
37-
ErrPackNotPurgeable = errors.New("pack not purgeable")
3837
ErrPdscEntryExists = errors.New("pdsc already in index")
3938
ErrPdscEntryNotFound = errors.New("pdsc not found in index")
4039
ErrEula = errors.New("user does not agree with the pack's license")

cmd/installer/pack.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ func isGlobal(packPath string) (bool, error) {
9999
// - toBeRemoved: A boolean indicating if the pack is to be removed.
100100
// - forceLatest: A boolean indicating if the latest version of the pack should be used.
101101
// - noLocal: A boolean indicating if local installations should be ignored.
102-
// - timeout: An integer specifying the timeout duration for network operations.
103102
//
104103
// Returns:
105104
// - *PackType: A pointer to the prepared PackType object.
106105
// - error: An error if any issues occur during preparation.
107-
func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool, timeout int) (*PackType, error) {
106+
func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool) (*PackType, error) {
108107
pack := &PackType{
109108
path: packPath,
110109
toBeRemoved: toBeRemoved,
@@ -158,10 +157,7 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
158157
}
159158

160159
if pdscTag.URL != "" {
161-
err = Installation.downloadPdscFile(pdscTag, false, timeout)
162-
if err != nil {
163-
return pack, err
164-
}
160+
pack.URL = pdscTag.URL
165161
}
166162

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

178172
return pack, nil
179173
}
@@ -276,11 +270,19 @@ func (p *PackType) validate() error {
276270
return errs.ErrPdscFileNotFound
277271
}
278272

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

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

294296
files, err := utils.ListDir(Installation.DownloadDir, fileNamePattern)
295297
if err != nil {
296-
return err
298+
return false, err
297299
}
298300

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

304307
for _, file := range files {
305308
if err := os.Remove(file); err != nil {
306-
return err
309+
return false, err
307310
}
308311
}
309312

310-
return nil
313+
return false, nil
311314
}
312315

313316
// install installs pack files to installation's directories
@@ -666,12 +669,12 @@ func (p *PackType) loadDependencies(nometa bool) error {
666669
var pack *PackType
667670
var err error
668671
if version == "" {
669-
pack, err = preparePack(deps[i][1]+"."+deps[i][0], false, false, false, nometa, 0)
672+
pack, err = preparePack(deps[i][1]+"."+deps[i][0], false, false, false, nometa)
670673
if err != nil {
671674
return err
672675
}
673676
} else {
674-
pack, err = preparePack(deps[i][1]+"."+deps[i][0]+"."+deps[i][2], false, false, false, nometa, 0)
677+
pack, err = preparePack(deps[i][1]+"."+deps[i][0]+"."+deps[i][2], false, false, false, nometa)
675678
if err != nil {
676679
return err
677680
}

cmd/installer/pdsc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (p *PdscType) install(installation *PacksInstallationType) error {
108108
}
109109
}
110110

111-
return Installation.LocalPidx.AddPdsc(tag)
111+
return installation.LocalPidx.AddPdsc(tag)
112112
}
113113

114114
// uninstall uninstalls a pack via PDSC

0 commit comments

Comments
 (0)