Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ Add a pack using the following "<pack>" specification or using packs provided by
return errs.ErrIncorrectCmdArgs
}

log.Debugf("Specified packs %v", args)
var lastErr error

log.Debugf("Specified packs %v", args)
installer.UnlockPackRoot()
for _, packPath := range args {
var err error
if filepath.Ext(packPath) == ".pdsc" {
err = installer.AddPdsc(packPath)
} else {
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, viper.GetInt("timeout"))
err = installer.AddPack(packPath, !addCmdFlags.skipEula, addCmdFlags.extractEula, addCmdFlags.forceReinstall, addCmdFlags.noRequirements, false, viper.GetInt("timeout"))
}
if err != nil {
lastErr = err
Expand Down
Empty file modified cmd/commands/checksum.go
100755 → 100644
Empty file.
3 changes: 3 additions & 0 deletions cmd/commands/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ The url is optional. Ex "cpackget connection https://www.keil.com/pack"`,
if err != nil {
return err
}
if err := installer.ReadIndexFiles(); err != nil {
return err
}
}

indexPath, err = installer.GetIndexPath(indexPath)
Expand Down
8 changes: 4 additions & 4 deletions cmd/commands/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ var connectionCmdTests = []TestCase{
expectedErr: nil,
},
{
name: "test checking invalid url",
args: []string{"connection", wrongURLPath},
expectedErr: errs.ErrOffline,
expErrUnwwrap: true,
name: "test checking invalid url",
args: []string{"connection", wrongURLPath},
expectedErr: errs.ErrOffline,
expErrUnwrap: true,
},

{ // set up environment for next test
Expand Down
6 changes: 5 additions & 1 deletion cmd/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot htt
}

installer.UnlockPackRoot()
defer installer.LockPackRoot()
if err := installer.ReadIndexFiles(); err != nil {
return err
}

err = installer.UpdatePublicIndex(indexPath, true, true, initCmdFlags.downloadPdscFiles, false, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
installer.LockPackRoot()
return err
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ListCmd = &cobra.Command{
Args: cobra.MaximumNArgs(0),
PersistentPreRunE: configureInstaller,
RunE: func(cmd *cobra.Command, args []string) error {
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, false, listCmdFlags.listFilter)
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, false, false, listCmdFlags.listFilter)
},
}

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

Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ please use "--purge".`,
err = errs.ErrPackNotInstalled
}
} else {
err = installer.RemovePack(packPath, rmCmdFlags.purge, viper.GetInt("timeout"))
err = installer.RemovePack(packPath, rmCmdFlags.purge, false, viper.GetInt("timeout"))
}
if err != nil {
if err != errs.ErrAlreadyLogged {
Expand Down
15 changes: 6 additions & 9 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,34 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
targetPackRoot := viper.GetString("pack-root")
checkConnection := viper.GetBool("check-connection") // TODO: never set

download := cmd.Name() != "init" && cmd.Name() != "update-index" && cmd.Name() != "rm" && cmd.Name() != "list" && cmd.Name() != "connection"

if targetPackRoot == installer.GetDefaultCmsisPackRoot() {
// If using the default pack root path and the public index is not found,
// initialize it
// If using the default pack root path and the public index is not found, initialize it
if !checkConnection && !utils.FileExists(filepath.Join(targetPackRoot, ".Web", installer.PublicIndex)) {
err := installer.SetPackRoot(targetPackRoot, true, true)
err := installer.SetPackRoot(targetPackRoot, true)
if err != nil {
return err
}
// Exclude index updating commands to not double update
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "rm" && cmd.Name() != "list" {
if cmd.Name() != "init" && cmd.Name() != "index" && cmd.Name() != "update-index" && cmd.Name() != "list" {
installer.UnlockPackRoot()
err = installer.UpdatePublicIndex(installer.DefaultPublicIndex, true, true, false, false, 0, 0)
if err != nil {
return err
}
err = installer.SetPackRoot(targetPackRoot, false, false)
err = installer.SetPackRoot(targetPackRoot, false)
if err != nil {
return err
}
installer.LockPackRoot()
}
} else {
err := installer.SetPackRoot(targetPackRoot, createPackRoot, download)
err := installer.SetPackRoot(targetPackRoot, createPackRoot)
if err != nil {
return err
}
}
} else {
err := installer.SetPackRoot(targetPackRoot, createPackRoot, download)
err := installer.SetPackRoot(targetPackRoot, createPackRoot)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type TestCase struct {
expectedStdout []string
expectedStderr []string
expectedErr error
expErrUnwwrap bool
expErrUnwrap bool
setUpFunc func(t *TestCase)
tearDownFunc func()
validationFunc func(t *testing.T)
Expand Down Expand Up @@ -144,8 +144,9 @@ func runTests(t *testing.T, tests []TestCase) {

os.Setenv("CMSIS_PACK_ROOT", localTestingDir)
if test.createPackRoot {
assert.Nil(installer.SetPackRoot(localTestingDir, test.createPackRoot, false))
assert.Nil(installer.SetPackRoot(localTestingDir, test.createPackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
}

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

if test.expErrUnwwrap {
if test.expErrUnwrap {
assert.Equal(test.expectedErr, errors.Unwrap(cmdErr))
} else {
assert.Equal(test.expectedErr, cmdErr)
Expand Down
9 changes: 7 additions & 2 deletions cmd/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ Update a pack using the following "<pack>" specification or using packs provided
The pack can be local file or hosted somewhere else on the Internet.
If it's hosted somewhere, cpackget will first download it then extract all pack files into "CMSIS_PACK_ROOT/<vendor>/<packName>/<x.y.z>/"
If "-f" is used, cpackget will call "cpackget update pack" on each URL specified in the <packs list> file.`,
Args: cobra.MinimumNArgs(0),
PersistentPreRunE: configureInstaller,
Args: cobra.MinimumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

utils.SetEncodedProgress(updateCmdFlags.encodedProgress)
utils.SetSkipTouch(updateCmdFlags.skipTouch)

createPackRoot = true
err := configureInstaller(cmd, args)
if err != nil {
return err
}

if updateCmdFlags.packsListFileName != "" {
log.Infof("Parsing packs urls via file %v", updateCmdFlags.packsListFileName)

Expand Down
23 changes: 16 additions & 7 deletions cmd/commands/update_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ var updateIndexCmdFlags struct {
}

var UpdateIndexCmd = &cobra.Command{
Use: "update-index",
Short: "Update the public index",
Long: getLongUpdateDescription(),
PersistentPreRunE: configureInstaller,
Args: cobra.ExactArgs(0),
Use: "update-index",
Short: "Update the public index",
Long: getLongUpdateDescription(),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
utils.SetEncodedProgress(updateIndexCmdFlags.encodedProgress)
utils.SetSkipTouch(updateIndexCmdFlags.skipTouch)

err := configureInstaller(cmd, args)
if err != nil {
return err
}

installer.UnlockPackRoot()
err := installer.UpdatePublicIndex("", true, updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
installer.LockPackRoot()
defer installer.LockPackRoot()
if err := installer.ReadIndexFiles(); err != nil {
return err
}

err = installer.UpdatePublicIndex("", true, updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
return err
},
}
Expand Down
27 changes: 24 additions & 3 deletions cmd/installer/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,20 @@ type PackType struct {
}
}

// preparePack does some sanity validation regarding pack name
// preparePack prepares a PackType object based on the provided parameters,
// it does some sanity validation regarding pack name
// and check if it's public and if it's installed or not
//
// Parameters:
// - packPath: The path or URL to the pack.
// - toBeRemoved: A boolean indicating if the pack is to be removed.
// - forceLatest: A boolean indicating if the latest version of the pack should be used.
// - noLocal: A boolean indicating if local installations should be ignored.
// - timeout: An integer specifying the timeout duration for network operations.
//
// Returns:
// - *PackType: A pointer to the prepared PackType object.
// - error: An error if any issues occur during preparation.
func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool, timeout int) (*PackType, error) {
pack := &PackType{
path: packPath,
Expand Down Expand Up @@ -132,9 +144,18 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
return pack, nil
}

// fetch will download the pack file if it's on the Internet, or
// will use the one in .Download/ if previously downloaded.
// If the path is not a URL, it will make sure the file exists in the local file system
// fetch downloads the pack file if the path is a URL or verifies its existence locally.
// If the path starts with "http", it attempts to download the file using the provided timeout.
// If the download is aborted by the user, it logs the event and removes the partially downloaded file.
// If the path is not a URL, it checks if the file exists locally.
// Returns an error if the file does not exist or if there is an issue during download.
//
// Parameters:
// - timeout: an integer specifying the timeout duration for the download operation.
//
// Returns:
// - error: an error object if the file does not exist or if there is an issue during download.
func (p *PackType) fetch(timeout int) error {
log.Debugf("Fetching pack file \"%s\" (or just making sure it exists locally)", p.path)
var err error
Expand Down
Loading
Loading