@@ -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 }
0 commit comments