Skip to content
2 changes: 1 addition & 1 deletion cmd/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Add a pack using the following "<pack>" specification or using packs provided by
installer.UnlockPackRoot()
for _, packPath := range args {
var err error
if filepath.Ext(packPath) == installer.PdscExtension {
if filepath.Ext(packPath) == utils.PdscExtension {
err = installer.AddPdsc(packPath)
} else {
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, false, viper.GetInt("timeout"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot htt
return err
}

err = installer.UpdatePublicIndex(indexPath, true, true, initCmdFlags.downloadPdscFiles, false, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
err = installer.UpdatePublicIndex(indexPath, true, initCmdFlags.downloadPdscFiles, false, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
return err
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ please use "--purge".`,
installer.UnlockPackRoot()
for _, packPath := range args {
var err error
if filepath.Ext(packPath) == installer.PdscExtension {
if filepath.Ext(packPath) == utils.PdscExtension {
err = installer.RemovePdsc(packPath)
if err == errs.ErrPdscEntryNotFound {
err = errs.ErrPackNotInstalled
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
// Exclude index updating commands to not double update
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "list" {
installer.UnlockPackRoot()
err = installer.UpdatePublicIndex(installer.ActualPublicIndex, true, true, false, false, false, true, 0, 0)
err = installer.UpdatePublicIndex(installer.ActualPublicIndex, true, false, false, false, true, 0, 0)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/update_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var UpdateIndexCmd = &cobra.Command{
return err
}

err = installer.UpdatePublicIndex("", true, updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
err = installer.UpdatePublicIndex("", updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
return err
},
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/cryptography/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
"github.com/open-cmsis-pack/cpackget/cmd/installer"
"github.com/open-cmsis-pack/cpackget/cmd/utils"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -64,7 +63,7 @@ func GenerateChecksum(sourcePack, destinationDir, hashFunction string) error {
if !utils.DirExists(destinationDir) {
return errs.ErrDirectoryNotFound
}
base = filepath.Clean(destinationDir) + string(filepath.Separator) + strings.TrimSuffix(string(filepath.Base(sourcePack)), installer.PackExtension)
base = filepath.Clean(destinationDir) + string(filepath.Separator) + strings.TrimSuffix(string(filepath.Base(sourcePack)), utils.PackExtension)
}
checksumFilename := base + "." + strings.ReplaceAll(hashFunction, "-", "") + ".checksum"
if utils.FileExists(checksumFilename) {
Expand Down Expand Up @@ -96,7 +95,7 @@ func VerifyChecksum(packPath, checksumPath string) error {
// exist .checksums with different algos in the same dir
if checksumPath == "" {
for _, hash := range Hashes {
checksumPath = strings.ReplaceAll(packPath, installer.PackExtension, "."+hash+".checksum")
checksumPath = strings.ReplaceAll(packPath, utils.PackExtension, "."+hash+".checksum")
if utils.FileExists(checksumPath) {
break
}
Expand Down
28 changes: 17 additions & 11 deletions cmd/installer/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
type PackType struct {
xml.PdscTag

//IsLocallySourced tells whether the pack's source is local or an HTTP URL
// IsLocallySourced tells whether the pack's source is local or an HTTP URL
IsLocallySourced bool

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

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

Expand Down Expand Up @@ -208,8 +208,7 @@ func (p *PackType) fetch(timeout int) error {
return nil
}

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

// Ensure all file paths do not contain ".."
if strings.Contains(file.Name, "..") {
if ext == PdscExtension {
if ext == utils.PdscExtension {
log.Errorf("File %q invalid file path", file.Name)
return errs.ErrInvalidFilePath
} else {
return errs.ErrInsecureZipFileName
}
}

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

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

cTag := xml.CacheTag{Vendor: p.Vendor, Name: p.Name, Version: p.Version}
if err = Installation.PublicCacheIndexXML.RemovePdsc(cTag); err == nil {
webFile := Installation.WebDir + "/" + p.VName() + utils.PdscExtension
files = append(files, webFile) // also add pdsc file in .Web
}
_ = Installation.PublicCacheIndexXML.Write()

log.Debugf("Files to be purged \"%v\"", files)
if len(files) == 0 {
log.Infof("pack %s.%s already removed from %s", p.path, p.Version, Installation.DownloadDir)
Expand Down Expand Up @@ -763,17 +769,17 @@ func (p *PackType) PackIDWithVersion() string {

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

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

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

// GetVersion makes sure to get the latest version for the pack
Expand Down
Loading
Loading