Skip to content

Commit a48871b

Browse files
committed
Introduced cache for PDSC files in .WEB. "Remove requirement that all PDSC files need to be updated," Issue #2217
1 parent b5c822e commit a48871b

File tree

15 files changed

+626
-196
lines changed

15 files changed

+626
-196
lines changed

cmd/commands/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Add a pack using the following "<pack>" specification or using packs provided by
100100
installer.UnlockPackRoot()
101101
for _, packPath := range args {
102102
var err error
103-
if filepath.Ext(packPath) == installer.PdscExtension {
103+
if filepath.Ext(packPath) == utils.PdscExtension {
104104
err = installer.AddPdsc(packPath)
105105
} else {
106106
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, false, viper.GetInt("timeout"))

cmd/commands/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot htt
5353
return err
5454
}
5555

56-
err = installer.UpdatePublicIndex(indexPath, true, true, initCmdFlags.downloadPdscFiles, false, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
56+
err = installer.UpdatePublicIndex(indexPath, true, initCmdFlags.downloadPdscFiles, false, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
5757
return err
5858
},
5959
}

cmd/commands/rm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ please use "--purge".`,
6060
installer.UnlockPackRoot()
6161
for _, packPath := range args {
6262
var err error
63-
if filepath.Ext(packPath) == installer.PdscExtension {
63+
if filepath.Ext(packPath) == utils.PdscExtension {
6464
err = installer.RemovePdsc(packPath)
6565
if err == errs.ErrPdscEntryNotFound {
6666
err = errs.ErrPackNotInstalled

cmd/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
7979
// Exclude index updating commands to not double update
8080
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "list" {
8181
installer.UnlockPackRoot()
82-
err = installer.UpdatePublicIndex(installer.ActualPublicIndex, true, true, false, false, false, true, 0, 0)
82+
err = installer.UpdatePublicIndex(installer.ActualPublicIndex, true, false, false, false, true, 0, 0)
8383
if err != nil {
8484
return err
8585
}

cmd/commands/update_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var UpdateIndexCmd = &cobra.Command{
4444
return err
4545
}
4646

47-
err = installer.UpdatePublicIndex("", true, updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
47+
err = installer.UpdatePublicIndex("", updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
4848
return err
4949
},
5050
}

cmd/cryptography/checksum.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
12-
"github.com/open-cmsis-pack/cpackget/cmd/installer"
1312
"github.com/open-cmsis-pack/cpackget/cmd/utils"
1413
log "github.com/sirupsen/logrus"
1514
)
@@ -64,7 +63,7 @@ func GenerateChecksum(sourcePack, destinationDir, hashFunction string) error {
6463
if !utils.DirExists(destinationDir) {
6564
return errs.ErrDirectoryNotFound
6665
}
67-
base = filepath.Clean(destinationDir) + string(filepath.Separator) + strings.TrimSuffix(string(filepath.Base(sourcePack)), installer.PackExtension)
66+
base = filepath.Clean(destinationDir) + string(filepath.Separator) + strings.TrimSuffix(string(filepath.Base(sourcePack)), utils.PackExtension)
6867
}
6968
checksumFilename := base + "." + strings.ReplaceAll(hashFunction, "-", "") + ".checksum"
7069
if utils.FileExists(checksumFilename) {
@@ -96,7 +95,7 @@ func VerifyChecksum(packPath, checksumPath string) error {
9695
// exist .checksums with different algos in the same dir
9796
if checksumPath == "" {
9897
for _, hash := range Hashes {
99-
checksumPath = strings.ReplaceAll(packPath, installer.PackExtension, "."+hash+".checksum")
98+
checksumPath = strings.ReplaceAll(packPath, utils.PackExtension, "."+hash+".checksum")
10099
if utils.FileExists(checksumPath) {
101100
break
102101
}

cmd/installer/pack.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
type PackType struct {
2727
xml.PdscTag
2828

29-
//IsLocallySourced tells whether the pack's source is local or an HTTP URL
29+
// IsLocallySourced tells whether the pack's source is local or an HTTP URL
3030
IsLocallySourced bool
3131

3232
// IsPublic tells whether the pack exists in the public index or not
@@ -155,7 +155,7 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
155155

156156
if pack.isPackID && nometa {
157157
if meta, found := utils.SemverHasMeta(pack.Version); found {
158-
return pack, fmt.Errorf("%w: %q. Expected vendor.pack.version", errs.ErrBadPackVersion, meta)
158+
return pack, fmt.Errorf("%w: %q. Expected vendor%s.version", errs.ErrBadPackVersion, meta, utils.PackExtension)
159159
}
160160
}
161161

@@ -208,8 +208,7 @@ func (p *PackType) fetch(timeout int) error {
208208
return nil
209209
}
210210

211-
// validate ensures the pack is legit and it has all minimal requirements
212-
// to be installed.
211+
// validate ensures the pack is legit and it has all minimal requirements to be installed.
213212
func (p *PackType) validate() error {
214213
log.Debug("Validating pack")
215214
var err error
@@ -222,15 +221,15 @@ func (p *PackType) validate() error {
222221

223222
// Ensure all file paths do not contain ".."
224223
if strings.Contains(file.Name, "..") {
225-
if ext == PdscExtension {
224+
if ext == utils.PdscExtension {
226225
log.Errorf("File %q invalid file path", file.Name)
227226
return errs.ErrInvalidFilePath
228227
} else {
229228
return errs.ErrInsecureZipFileName
230229
}
231230
}
232231

233-
if ext == PdscExtension {
232+
if ext == utils.PdscExtension {
234233
// Check if pack was compressed in a subfolder
235234
subfoldersCount := strings.Count(file.Name, "/") + strings.Count(file.Name, "\\")
236235
if subfoldersCount > 1 {
@@ -239,7 +238,7 @@ func (p *PackType) validate() error {
239238
tmpFileName := filepath.Base(file.Name) // normalize file name
240239
if !strings.EqualFold(tmpFileName, myPdscFileName) {
241240
if err != nil {
242-
log.Warnf("Pack %q contains an additional .pdsc file in a deeper subfolder, this may cause issues", p.path)
241+
log.Warnf("Pack %q contains an additional %s file in a deeper subfolder, this may cause issues", p.path, utils.PdscExtension)
243242
}
244243
return fmt.Errorf("%q: %w", file.Name, errs.ErrPdscWrongName)
245244
}
@@ -259,7 +258,7 @@ func (p *PackType) validate() error {
259258

260259
if err != nil {
261260
if len(validPdscFiles) > 0 {
262-
log.Warnf("Pack %q contains an additional .pdsc file in a deeper subfolder, this may cause issues", p.path)
261+
log.Warnf("Pack %q contains an additional %s file in a deeper subfolder, this may cause issues", p.path, utils.PdscExtension)
263262
} else {
264263
return err
265264
}
@@ -346,6 +345,13 @@ func (p *PackType) purge() (bool, error) {
346345
return false, err
347346
}
348347

348+
cTag := xml.CacheTag{Vendor: p.Vendor, Name: p.Name, Version: p.Version}
349+
if err = Installation.PublicCacheIndexXML.RemovePdsc(cTag); err == nil {
350+
webFile := Installation.WebDir + "/" + p.VName() + utils.PdscExtension
351+
files = append(files, webFile) // also add pdsc file in .Web
352+
}
353+
_ = Installation.PublicCacheIndexXML.Write()
354+
349355
log.Debugf("Files to be purged \"%v\"", files)
350356
if len(files) == 0 {
351357
log.Infof("pack %s.%s already removed from %s", p.path, p.Version, Installation.DownloadDir)
@@ -763,17 +769,17 @@ func (p *PackType) PackIDWithVersion() string {
763769

764770
// PackFileName returns a string with how the pack file name would be: Vendor.PackName.x.y.z.pack
765771
func (p *PackType) PackFileName() string {
766-
return p.PackIDWithVersion() + PackExtension
772+
return p.PackIDWithVersion() + utils.PackExtension
767773
}
768774

769775
// PdscFileName returns a string with how the pack's pdsc file name would be: Vendor.PackName.pdsc
770776
func (p *PackType) PdscFileName() string {
771-
return p.PackID() + PdscExtension
777+
return p.PackID() + utils.PdscExtension
772778
}
773779

774780
// PdscFileNameWithVersion returns a string with how the pack's pdsc file name would be: Vendor.PackName.x.y.z.pdsc
775781
func (p *PackType) PdscFileNameWithVersion() string {
776-
return p.PackIDWithVersion() + PdscExtension
782+
return p.PackIDWithVersion() + utils.PdscExtension
777783
}
778784

779785
// GetVersion makes sure to get the latest version for the pack

0 commit comments

Comments
 (0)