Skip to content

Commit a31392f

Browse files
authored
issue #404, moved download of index.pidx after decision if only local… (#469)
… packs are concerned ## Fixes #404 ## Changes most sources and tests ## 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 3fd39fb commit a31392f

24 files changed

+906
-337
lines changed

cmd/commands/add.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,16 @@ Add a pack using the following "<pack>" specification or using packs provided by
114114
return errs.ErrIncorrectCmdArgs
115115
}
116116

117-
log.Debugf("Specified packs %v", args)
118117
var lastErr error
118+
119+
log.Debugf("Specified packs %v", args)
119120
installer.UnlockPackRoot()
120121
for _, packPath := range args {
121122
var err error
122123
if filepath.Ext(packPath) == ".pdsc" {
123124
err = installer.AddPdsc(packPath)
124125
} else {
125-
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, viper.GetInt("timeout"))
126+
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, false, viper.GetInt("timeout"))
126127
}
127128
if err != nil {
128129
lastErr = err

cmd/commands/checksum.go

100755100644
File mode changed.

cmd/commands/connection.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ The url is optional. Ex "cpackget connection https://www.keil.com/pack"`,
4545
if err != nil {
4646
return err
4747
}
48+
if err := installer.ReadIndexFiles(); err != nil {
49+
return err
50+
}
4851
}
4952

5053
indexPath, err = installer.GetIndexPath(indexPath)

cmd/commands/connection_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ var connectionCmdTests = []TestCase{
2727
expectedErr: nil,
2828
},
2929
{
30-
name: "test checking invalid url",
31-
args: []string{"connection", wrongURLPath},
32-
expectedErr: errs.ErrOffline,
33-
expErrUnwwrap: true,
30+
name: "test checking invalid url",
31+
args: []string{"connection", wrongURLPath},
32+
expectedErr: errs.ErrOffline,
33+
expErrUnwrap: true,
3434
},
3535

3636
{ // set up environment for next test

cmd/commands/init.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot htt
4848
}
4949

5050
installer.UnlockPackRoot()
51+
defer installer.LockPackRoot()
52+
if err := installer.ReadIndexFiles(); err != nil {
53+
return err
54+
}
55+
5156
err = installer.UpdatePublicIndex(indexPath, true, true, initCmdFlags.downloadPdscFiles, false, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
52-
installer.LockPackRoot()
5357
return err
5458
},
5559
}

cmd/commands/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var ListCmd = &cobra.Command{
3030
Args: cobra.MaximumNArgs(0),
3131
PersistentPreRunE: configureInstaller,
3232
RunE: func(cmd *cobra.Command, args []string) error {
33-
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, false, listCmdFlags.listFilter)
33+
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, false, false, listCmdFlags.listFilter)
3434
},
3535
}
3636

@@ -41,7 +41,7 @@ var listRequiredCmd = &cobra.Command{
4141
Args: cobra.MaximumNArgs(0),
4242
PersistentPreRunE: configureInstaller,
4343
RunE: func(cmd *cobra.Command, args []string) error {
44-
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, true, listCmdFlags.listFilter)
44+
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, true, false, listCmdFlags.listFilter)
4545
},
4646
}
4747

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, viper.GetInt("timeout"))
69+
err = installer.RemovePack(packPath, rmCmdFlags.purge, false, viper.GetInt("timeout"))
7070
}
7171
if err != nil {
7272
if err != errs.ErrAlreadyLogged {

cmd/commands/root.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,34 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
6969
targetPackRoot := viper.GetString("pack-root")
7070
checkConnection := viper.GetBool("check-connection") // TODO: never set
7171

72-
download := cmd.Name() != "init" && cmd.Name() != "update-index" && cmd.Name() != "rm" && cmd.Name() != "list" && cmd.Name() != "connection"
73-
7472
if targetPackRoot == installer.GetDefaultCmsisPackRoot() {
75-
// If using the default pack root path and the public index is not found,
76-
// initialize it
73+
// If using the default pack root path and the public index is not found, initialize it
7774
if !checkConnection && !utils.FileExists(filepath.Join(targetPackRoot, ".Web", installer.PublicIndex)) {
78-
err := installer.SetPackRoot(targetPackRoot, true, true)
75+
err := installer.SetPackRoot(targetPackRoot, true)
7976
if err != nil {
8077
return err
8178
}
8279
// Exclude index updating commands to not double update
83-
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "rm" && cmd.Name() != "list" {
80+
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "list" {
8481
installer.UnlockPackRoot()
8582
err = installer.UpdatePublicIndex(installer.DefaultPublicIndex, true, true, false, false, 0, 0)
8683
if err != nil {
8784
return err
8885
}
89-
err = installer.SetPackRoot(targetPackRoot, false, false)
86+
err = installer.SetPackRoot(targetPackRoot, false)
9087
if err != nil {
9188
return err
9289
}
9390
installer.LockPackRoot()
9491
}
9592
} else {
96-
err := installer.SetPackRoot(targetPackRoot, createPackRoot, download)
93+
err := installer.SetPackRoot(targetPackRoot, createPackRoot)
9794
if err != nil {
9895
return err
9996
}
10097
}
10198
} else {
102-
err := installer.SetPackRoot(targetPackRoot, createPackRoot, download)
99+
err := installer.SetPackRoot(targetPackRoot, createPackRoot)
103100
if err != nil {
104101
return err
105102
}

cmd/commands/root_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type TestCase struct {
4242
expectedStdout []string
4343
expectedStderr []string
4444
expectedErr error
45-
expErrUnwwrap bool
45+
expErrUnwrap bool
4646
setUpFunc func(t *TestCase)
4747
tearDownFunc func()
4848
validationFunc func(t *testing.T)
@@ -144,8 +144,9 @@ func runTests(t *testing.T, tests []TestCase) {
144144

145145
os.Setenv("CMSIS_PACK_ROOT", localTestingDir)
146146
if test.createPackRoot {
147-
assert.Nil(installer.SetPackRoot(localTestingDir, test.createPackRoot, false))
147+
assert.Nil(installer.SetPackRoot(localTestingDir, test.createPackRoot))
148148
installer.UnlockPackRoot()
149+
assert.Nil(installer.ReadIndexFiles())
149150
}
150151

151152
if test.env != nil {
@@ -201,7 +202,7 @@ func runTests(t *testing.T, tests []TestCase) {
201202
outStr := string(outBytes)
202203
errStr := string(errBytes)
203204

204-
if test.expErrUnwwrap {
205+
if test.expErrUnwrap {
205206
assert.Equal(test.expectedErr, errors.Unwrap(cmdErr))
206207
} else {
207208
assert.Equal(test.expectedErr, cmdErr)

cmd/commands/update.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ Update a pack using the following "<pack>" specification or using packs provided
4949
The pack can be local file or hosted somewhere else on the Internet.
5050
If it's hosted somewhere, cpackget will first download it then extract all pack files into "CMSIS_PACK_ROOT/<vendor>/<packName>/<x.y.z>/"
5151
If "-f" is used, cpackget will call "cpackget update pack" on each URL specified in the <packs list> file.`,
52-
Args: cobra.MinimumNArgs(0),
53-
PersistentPreRunE: configureInstaller,
52+
Args: cobra.MinimumNArgs(0),
5453
RunE: func(cmd *cobra.Command, args []string) error {
5554

5655
utils.SetEncodedProgress(updateCmdFlags.encodedProgress)
5756
utils.SetSkipTouch(updateCmdFlags.skipTouch)
5857

58+
createPackRoot = true
59+
err := configureInstaller(cmd, args)
60+
if err != nil {
61+
return err
62+
}
63+
5964
if updateCmdFlags.packsListFileName != "" {
6065
log.Infof("Parsing packs urls via file %v", updateCmdFlags.packsListFileName)
6166

0 commit comments

Comments
 (0)