Skip to content

Commit 009dcf8

Browse files
committed
Moved upgradePlatform into a packagamanger method
1 parent 7a15631 commit 009dcf8

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

arduino/cores/packagemanager/install_uninstall.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,45 @@ import (
2929
"github.com/pkg/errors"
3030
)
3131

32+
// DownloadAndInstallPlatformUpgrades runs a full installation process to upgrade the given platform.
33+
// This methods taks care of downloading missing archives, upgrade platforms and tools, and
34+
// remove the previously installed platform/tools that are no more needed after the upgrade.
35+
func (pm *PackageManager) DownloadAndInstallPlatformUpgrades(
36+
platformRef *PlatformReference,
37+
downloadCB rpc.DownloadProgressCB,
38+
taskCB rpc.TaskProgressCB,
39+
skipPostInstall bool,
40+
) error {
41+
if platformRef.PlatformVersion != nil {
42+
return &arduino.InvalidArgumentError{Message: tr("Upgrade doesn't accept parameters with version")}
43+
}
44+
45+
// Search the latest version for all specified platforms
46+
platform := pm.FindPlatform(platformRef)
47+
if platform == nil {
48+
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
49+
}
50+
installed := pm.GetInstalledPlatformRelease(platform)
51+
if installed == nil {
52+
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
53+
}
54+
latest := platform.GetLatestRelease()
55+
if !latest.Version.GreaterThan(installed.Version) {
56+
return &arduino.PlatformAlreadyAtTheLatestVersionError{}
57+
}
58+
platformRef.PlatformVersion = latest.Version
59+
60+
platformRelease, tools, err := pm.FindPlatformReleaseDependencies(platformRef)
61+
if err != nil {
62+
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
63+
}
64+
if err := pm.DownloadAndInstallPlatformAndTools(platformRelease, tools, downloadCB, taskCB, skipPostInstall); err != nil {
65+
return err
66+
}
67+
68+
return nil
69+
}
70+
3271
// DownloadAndInstallPlatformAndTools runs a full installation process for the given platform and tools.
3372
// This methods taks care of downloading missing archives, install/upgrade platforms and tools, and
3473
// remove the previously installed platform/tools that are no more needed after the upgrade.

commands/core/upgrade.go

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
3838
Package: req.PlatformPackage,
3939
PlatformArchitecture: req.Architecture,
4040
}
41-
if err := upgradePlatform(pm, ref, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
41+
if err := pm.DownloadAndInstallPlatformUpgrades(ref, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
4242
return nil, err
4343
}
4444

@@ -48,35 +48,3 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
4848

4949
return &rpc.PlatformUpgradeResponse{}, nil
5050
}
51-
52-
func upgradePlatform(pm *packagemanager.PackageManager, platformRef *packagemanager.PlatformReference,
53-
downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, skipPostInstall bool) error {
54-
if platformRef.PlatformVersion != nil {
55-
return &arduino.InvalidArgumentError{Message: tr("Upgrade doesn't accept parameters with version")}
56-
}
57-
58-
// Search the latest version for all specified platforms
59-
platform := pm.FindPlatform(platformRef)
60-
if platform == nil {
61-
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
62-
}
63-
installed := pm.GetInstalledPlatformRelease(platform)
64-
if installed == nil {
65-
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
66-
}
67-
latest := platform.GetLatestRelease()
68-
if !latest.Version.GreaterThan(installed.Version) {
69-
return &arduino.PlatformAlreadyAtTheLatestVersionError{}
70-
}
71-
platformRef.PlatformVersion = latest.Version
72-
73-
platformRelease, tools, err := pm.FindPlatformReleaseDependencies(platformRef)
74-
if err != nil {
75-
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
76-
}
77-
if err := pm.DownloadAndInstallPlatformAndTools(platformRelease, tools, downloadCB, taskCB, skipPostInstall); err != nil {
78-
return err
79-
}
80-
81-
return nil
82-
}

0 commit comments

Comments
 (0)