Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6e00737

Browse filesBrowse files
committed
PlatformInstall/Uninstall must release PackageManager.Explorer before calling commands.Init
Otherwise, since Init will try to take a write-lock, it will block indefinitely.
1 parent 840c703 commit 6e00737
Copy full SHA for 6e00737

File tree

Expand file treeCollapse file tree

3 files changed

+69
-32
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+69
-32
lines changed

‎commands/core/install.go

Copy file name to clipboardExpand all lines: commands/core/install.go
+28-13Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,37 @@ import (
2626
)
2727

2828
// PlatformInstall FIXMEDOC
29-
func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
30-
downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) {
29+
func PlatformInstall(
30+
ctx context.Context,
31+
req *rpc.PlatformInstallRequest,
32+
downloadCB rpc.DownloadProgressCB,
33+
taskCB rpc.TaskProgressCB,
34+
) (*rpc.PlatformInstallResponse, error) {
35+
if err := platformInstall(ctx, req, downloadCB, taskCB); err != nil {
36+
return nil, err
37+
}
38+
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
39+
return nil, err
40+
}
41+
return &rpc.PlatformInstallResponse{}, nil
42+
}
3143

44+
// platformInstall is the implementation of platform install
45+
func platformInstall(
46+
ctx context.Context,
47+
req *rpc.PlatformInstallRequest,
48+
downloadCB rpc.DownloadProgressCB,
49+
taskCB rpc.TaskProgressCB,
50+
) error {
3251
pme, release := commands.GetPackageManagerExplorer(req)
3352
if pme == nil {
34-
return nil, &arduino.InvalidInstanceError{}
53+
return &arduino.InvalidInstanceError{}
3554
}
3655
defer release()
3756

3857
version, err := commands.ParseVersion(req)
3958
if err != nil {
40-
return nil, &arduino.InvalidVersionError{Cause: err}
59+
return &arduino.InvalidVersionError{Cause: err}
4160
}
4261

4362
ref := &packagemanager.PlatformReference{
@@ -47,30 +66,26 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
4766
}
4867
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref)
4968
if err != nil {
50-
return nil, &arduino.PlatformNotFoundError{Platform: ref.String(), Cause: err}
69+
return &arduino.PlatformNotFoundError{Platform: ref.String(), Cause: err}
5170
}
5271

5372
// Prerequisite checks before install
5473
if platformRelease.IsInstalled() {
5574
taskCB(&rpc.TaskProgress{Name: tr("Platform %s already installed", platformRelease), Completed: true})
56-
return &rpc.PlatformInstallResponse{}, nil
75+
return nil
5776
}
5877

5978
if req.GetNoOverwrite() {
6079
if installed := pme.GetInstalledPlatformRelease(platformRelease.Platform); installed != nil {
61-
return nil, fmt.Errorf("%s: %s",
80+
return fmt.Errorf("%s: %s",
6281
tr("Platform %s already installed", installed),
6382
tr("could not overwrite"))
6483
}
6584
}
6685

6786
if err := pme.DownloadAndInstallPlatformAndTools(platformRelease, tools, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
68-
return nil, err
69-
}
70-
71-
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
72-
return nil, err
87+
return err
7388
}
7489

75-
return &rpc.PlatformInstallResponse{}, nil
90+
return nil
7691
}

‎commands/core/uninstall.go

Copy file name to clipboardExpand all lines: commands/core/uninstall.go
+17-10Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,20 @@ import (
2626

2727
// PlatformUninstall FIXMEDOC
2828
func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) (*rpc.PlatformUninstallResponse, error) {
29+
if err := platformUninstall(ctx, req, taskCB); err != nil {
30+
return nil, err
31+
}
32+
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
33+
return nil, err
34+
}
35+
return &rpc.PlatformUninstallResponse{}, nil
36+
}
37+
38+
// platformUninstall is the implementation of platform unistaller
39+
func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) error {
2940
pme, release := commands.GetPackageManagerExplorer(req)
3041
if pme == nil {
31-
return nil, &arduino.InvalidInstanceError{}
42+
return &arduino.InvalidInstanceError{}
3243
}
3344
defer release()
3445

@@ -39,22 +50,22 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
3950
if ref.PlatformVersion == nil {
4051
platform := pme.FindPlatform(ref)
4152
if platform == nil {
42-
return nil, &arduino.PlatformNotFoundError{Platform: ref.String()}
53+
return &arduino.PlatformNotFoundError{Platform: ref.String()}
4354
}
4455
platformRelease := pme.GetInstalledPlatformRelease(platform)
4556
if platformRelease == nil {
46-
return nil, &arduino.PlatformNotFoundError{Platform: ref.String()}
57+
return &arduino.PlatformNotFoundError{Platform: ref.String()}
4758
}
4859
ref.PlatformVersion = platformRelease.Version
4960
}
5061

5162
platform, tools, err := pme.FindPlatformReleaseDependencies(ref)
5263
if err != nil {
53-
return nil, &arduino.NotFoundError{Message: tr("Can't find dependencies for platform %s", ref), Cause: err}
64+
return &arduino.NotFoundError{Message: tr("Can't find dependencies for platform %s", ref), Cause: err}
5465
}
5566

5667
if err := pme.UninstallPlatform(platform, taskCB); err != nil {
57-
return nil, err
68+
return err
5869
}
5970

6071
for _, tool := range tools {
@@ -64,9 +75,5 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
6475
}
6576
}
6677

67-
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
68-
return nil, err
69-
}
70-
71-
return &rpc.PlatformUninstallResponse{}, nil
78+
return nil
7279
}

‎commands/core/upgrade.go

Copy file name to clipboardExpand all lines: commands/core/upgrade.go
+24-9Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,31 @@ import (
2525
)
2626

2727
// PlatformUpgrade FIXMEDOC
28-
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
29-
downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) {
28+
func PlatformUpgrade(
29+
ctx context.Context,
30+
req *rpc.PlatformUpgradeRequest,
31+
downloadCB rpc.DownloadProgressCB,
32+
taskCB rpc.TaskProgressCB,
33+
) (*rpc.PlatformUpgradeResponse, error) {
34+
if err := platformUpgrade(ctx, req, downloadCB, taskCB); err != nil {
35+
return nil, err
36+
}
37+
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
38+
return nil, err
39+
}
40+
return &rpc.PlatformUpgradeResponse{}, nil
41+
}
3042

43+
// platformUpgrade implements the platform upgrade procedure
44+
func platformUpgrade(
45+
ctx context.Context,
46+
req *rpc.PlatformUpgradeRequest,
47+
downloadCB rpc.DownloadProgressCB,
48+
taskCB rpc.TaskProgressCB,
49+
) error {
3150
pme, release := commands.GetPackageManagerExplorer(req)
3251
if pme == nil {
33-
return nil, &arduino.InvalidInstanceError{}
52+
return &arduino.InvalidInstanceError{}
3453
}
3554
defer release()
3655

@@ -40,12 +59,8 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
4059
PlatformArchitecture: req.Architecture,
4160
}
4261
if err := pme.DownloadAndInstallPlatformUpgrades(ref, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
43-
return nil, err
44-
}
45-
46-
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
47-
return nil, err
62+
return err
4863
}
4964

50-
return &rpc.PlatformUpgradeResponse{}, nil
65+
return nil
5166
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.