Skip to content

Commit 45e9d58

Browse files
authored
Issue 480, improve performance of update-index (#496)
## Fixes #480 ## Changes - maintain version info in index.pidx with current downloaded pdsc files - added list of pdsc's with download errors to return to old version in index.pidx ## 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). - [ ] 🛡️ Security impacts have been considered (if relevant). - [ ] 📖 Documentation updates are complete (if required). - [ ] 🧠 Third-party dependencies and TPIP updated (if required).
1 parent 8e54714 commit 45e9d58

File tree

18 files changed

+886
-360
lines changed

18 files changed

+886
-360
lines changed

cmd/commands/connection.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,7 @@ The url is optional. Ex "cpackget connection https://www.keil.com/pack"`,
4141
var err error
4242

4343
if indexPath == "" { // try to fetch from environment
44-
err = configureInstaller(cmd, args)
45-
if err != nil {
46-
return err
47-
}
48-
if err := installer.ReadIndexFiles(); err != nil {
49-
return err
50-
}
51-
}
52-
53-
indexPath, err = installer.GetIndexPath(indexPath)
54-
if err != nil {
55-
return err
44+
indexPath = installer.ConnectionTryURL
5645
}
5746

5847
err = utils.CheckConnection(indexPath, viper.GetInt("timeout"))

cmd/commands/connection_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var connectionCmdTests = []TestCase{
3939
noCleanup: true,
4040
setUpFunc: func(t *TestCase) {
4141
server := NewServer()
42-
t.args = append(t.args, server.URL()+installer.PublicIndex)
43-
server.AddRoute(installer.PublicIndex, []byte(`<?xml version="1.0" encoding="UTF-8" ?>
42+
t.args = append(t.args, server.URL()+installer.PublicIndexName)
43+
server.AddRoute(installer.PublicIndexName, []byte(`<?xml version="1.0" encoding="UTF-8" ?>
4444
<index schemaVersion="1.1.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="https://www.w3.org/2001/XMLSchema-instance">
4545
<vendor>TheVendor</vendor>
4646
<url>https://www.keil.com/</url>

cmd/commands/init_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
var (
2020
pidxFilePath = filepath.Join(testingDir, "SamplePublicIndex.pidx")
21-
notFoundPidxFilePath = filepath.Join("path", "to", installer.PublicIndex)
21+
notFoundPidxFilePath = filepath.Join("path", "to", installer.PublicIndexName)
2222
)
2323

2424
var initCmdTests = []TestCase{
@@ -33,12 +33,12 @@ var initCmdTests = []TestCase{
3333
expectedErr: nil,
3434
},
3535
{
36-
name: "test create using an " + installer.PublicIndex,
36+
name: "test create using an " + installer.PublicIndexName,
3737
args: []string{"init"},
3838
setUpFunc: func(t *TestCase) {
3939
server := NewServer()
40-
t.args = append(t.args, server.URL()+installer.PublicIndex)
41-
server.AddRoute(installer.PublicIndex, []byte(`<?xml version="1.0" encoding="UTF-8" ?>
40+
t.args = append(t.args, server.URL()+installer.PublicIndexName)
41+
server.AddRoute(installer.PublicIndexName, []byte(`<?xml version="1.0" encoding="UTF-8" ?>
4242
<index schemaVersion="1.1.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="https://www.w3.org/2001/XMLSchema-instance">
4343
<vendor>TheVendor</vendor>
4444
<url>https://the.vendor/</url>
@@ -50,12 +50,12 @@ var initCmdTests = []TestCase{
5050
},
5151
},
5252
{
53-
name: "test create using local " + installer.PublicIndex,
53+
name: "test create using local " + installer.PublicIndexName,
5454
args: []string{"init", pidxFilePath},
5555
createPackRoot: true,
5656
},
5757
{
58-
name: "test create using local " + installer.PublicIndex + " that does not exist",
58+
name: "test create using local " + installer.PublicIndexName + " that does not exist",
5959
args: []string{"init", notFoundPidxFilePath},
6060
createPackRoot: true,
6161
expectedErr: errs.ErrFileNotFoundUseInit,

cmd/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
7171

7272
if targetPackRoot == installer.GetDefaultCmsisPackRoot() {
7373
// If using the default pack root path and the public index is not found, initialize it
74-
if !checkConnection && !utils.FileExists(filepath.Join(targetPackRoot, ".Web", installer.PublicIndex)) {
74+
if !checkConnection && !utils.FileExists(filepath.Join(targetPackRoot, ".Web", installer.PublicIndexName)) {
7575
err := installer.SetPackRoot(targetPackRoot, true)
7676
if err != nil {
7777
return err

cmd/commands/update_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var UpdateIndexCmd = &cobra.Command{
5050
}
5151

5252
func getLongUpdateDescription() string {
53-
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + "/.Web/" + installer.PublicIndex + " using the URL in <url> tag inside " + installer.PublicIndex + `.
53+
return `Updates the public index in ` + os.Getenv("CMSIS_PACK_ROOT") + "/.Web/" + installer.PublicIndexName + " using the URL in <url> tag inside " + installer.PublicIndexName + `.
5454
By default it will also check if all PDSC files under .Web/ need update as well. This can be disabled via the "--sparse" flag.`
5555
}
5656

cmd/commands/update_index_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var updateIndexServer Server
1616
var updateIndexCmdTests = []TestCase{
1717
{
1818
name: "test no parameter is required",
19-
args: []string{"update-index", installer.PublicIndex},
19+
args: []string{"update-index", installer.PublicIndexName},
2020
expectedErr: errors.New("accepts 0 arg(s), received 1"),
2121
},
2222
{
@@ -29,7 +29,7 @@ var updateIndexCmdTests = []TestCase{
2929
args: []string{"update-index"},
3030
createPackRoot: true,
3131
defaultMode: true,
32-
expectedStdout: []string{"Updating public index", "Downloading " + installer.PublicIndex},
32+
expectedStdout: []string{"Updating public index", "Downloading " + installer.PublicIndexName},
3333
setUpFunc: func(t *TestCase) {
3434
indexContent := `<?xml version="1.0" encoding="UTF-8" ?>
3535
<index schemaVersion="1.1.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
@@ -43,14 +43,14 @@ var updateIndexCmdTests = []TestCase{
4343
indexContent = fmt.Sprintf(indexContent, updateIndexServer.URL())
4444
_ = os.WriteFile(installer.Installation.PublicIndex, []byte(indexContent), 0600)
4545

46-
updateIndexServer.AddRoute(installer.PublicIndex, []byte(indexContent))
46+
updateIndexServer.AddRoute(installer.PublicIndexName, []byte(indexContent))
4747
},
4848
},
4949
{
5050
name: "test updating index",
5151
args: []string{"update-index"},
5252
createPackRoot: true,
53-
expectedStdout: []string{"Updating public index", "Downloading " + installer.PublicIndex},
53+
expectedStdout: []string{"Updating public index", "Downloading " + installer.PublicIndexName},
5454
setUpFunc: func(t *TestCase) {
5555
indexContent := `<?xml version="1.0" encoding="UTF-8" ?>
5656
<index schemaVersion="1.1.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
@@ -64,7 +64,7 @@ var updateIndexCmdTests = []TestCase{
6464
indexContent = fmt.Sprintf(indexContent, updateIndexServer.URL())
6565
_ = os.WriteFile(installer.Installation.PublicIndex, []byte(indexContent), 0600)
6666

67-
updateIndexServer.AddRoute(installer.PublicIndex, []byte(indexContent))
67+
updateIndexServer.AddRoute(installer.PublicIndexName, []byte(indexContent))
6868
},
6969
},
7070
}

cmd/installer/pack.go

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ type PackType struct {
3232
// IsPublic tells whether the pack exists in the public index or not
3333
IsPublic bool
3434

35-
// isInstalled tells whether the pack is already installed
36-
isInstalled bool
37-
3835
// isDownloaded tells whether the file needed to be downloaded from a server
3936
isDownloaded bool
4037

@@ -51,6 +48,12 @@ type PackType struct {
5148
// targetVersion is the most recent version of a pack in case exactVersion==true
5249
targetVersion string
5350

51+
// isInstalled tells whether the pack is already installed
52+
isInstalled bool
53+
54+
// list of all the packs that are installed
55+
installedVersions []string
56+
5457
// path points to a file in the local system, whether or not it's local
5558
path string
5659

@@ -73,6 +76,20 @@ type PackType struct {
7376
}
7477
}
7578

79+
func isGlobal(packPath string) (bool, error) {
80+
info, err := utils.ExtractPackInfo(packPath)
81+
if err != nil {
82+
return false, err
83+
}
84+
if info.IsPackID {
85+
return true, nil
86+
}
87+
if !strings.HasPrefix(info.Location, "http://") && !strings.HasPrefix(info.Location, "https://") && strings.HasPrefix(info.Location, "file://") {
88+
return true, nil
89+
}
90+
return false, nil
91+
}
92+
7693
// preparePack prepares a PackType object based on the provided parameters,
7794
// it does some sanity validation regarding pack name
7895
// and check if it's public and if it's installed or not
@@ -119,8 +136,8 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
119136
info.VersionModifier = utils.LatestVersion
120137
}
121138
pack.URL = info.Location
122-
pack.Name = info.Pack
123139
pack.Vendor = info.Vendor
140+
pack.Name = info.Pack
124141
pack.Version = info.Version
125142
pack.versionModifier = info.VersionModifier
126143
pack.isPackID = info.IsPackID
@@ -129,7 +146,8 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
129146
pack.IsLocallySourced = true
130147
}
131148

132-
if pack.IsPublic, err = Installation.packIsPublic(pack, timeout); err != nil {
149+
var pdscTag xml.PdscTag
150+
if pack.IsPublic, err = Installation.packIsPublic(pack, &pdscTag); err != nil {
133151
return pack, err
134152
}
135153

@@ -139,7 +157,23 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
139157
}
140158
}
141159

142-
pack.isInstalled = Installation.PackIsInstalled(pack, noLocal)
160+
if pdscTag.URL != "" {
161+
err = Installation.downloadPdscFile(pdscTag, false, timeout)
162+
if err != nil {
163+
return pack, err
164+
}
165+
}
166+
167+
pack.isInstalled, pack.installedVersions = Installation.PackIsInstalled(pack, noLocal)
168+
169+
if pdscTag.Vendor != "" {
170+
pack.Vendor = pdscTag.Vendor
171+
}
172+
if pdscTag.Name != "" {
173+
pack.Name = pdscTag.Name
174+
}
175+
// pack.Version = pdscTag.Version
176+
// pack.URL = pdscTag.URL
143177

144178
return pack, nil
145179
}
@@ -343,8 +377,11 @@ func (p *PackType) install(installation *PacksInstallationType, checkEula bool)
343377
return err
344378
}
345379

346-
log.Debugf("Extracting files from \"%s\" to \"%s\"", p.path, packHomeDir)
347-
log.Infof("Extracting files to %s...", packHomeDir)
380+
if log.IsLevelEnabled(log.DebugLevel) {
381+
log.Debugf("Extracting files from \"%s\" to \"%s\"", p.path, packHomeDir)
382+
} else {
383+
log.Infof("Extracting files to %s...", packHomeDir)
384+
}
348385
// Avoid repeated calls to IsTerminalInteractive
349386
// as it cleans the stdout buffer
350387
interactiveTerminal := utils.IsTerminalInteractive()
@@ -650,7 +687,7 @@ func (p *PackType) loadDependencies(nometa bool) error {
650687
} else {
651688
pack.versionModifier = utils.LatestVersion
652689
}
653-
if Installation.PackIsInstalled(pack, false) {
690+
if ok, _ := Installation.PackIsInstalled(pack, false); ok {
654691
p.Requirements.packages = append(p.Requirements.packages, struct {
655692
info []string
656693
installed bool

0 commit comments

Comments
 (0)