Skip to content

Commit 2f3fe0b

Browse files
committed
Moved uninstallPlatformRelease into the proper packagamanger method
1 parent 4645260 commit 2f3fe0b

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

arduino/cores/packagemanager/install_uninstall.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,35 @@ func (pm *PackageManager) IsManagedPlatformRelease(platformRelease *cores.Platfo
111111
}
112112

113113
// UninstallPlatform remove a PlatformRelease.
114-
func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelease) error {
114+
func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelease, taskCB rpc.TaskProgressCB) error {
115+
log := pm.Log.WithField("platform", platformRelease)
116+
117+
log.Info("Uninstalling platform")
118+
taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", platformRelease)})
119+
115120
if platformRelease.InstallDir == nil {
116-
return fmt.Errorf(tr("platform not installed"))
121+
err := fmt.Errorf(tr("platform not installed"))
122+
log.WithError(err).Error("Error uninstalling")
123+
return &arduino.FailedUninstallError{Message: err.Error()}
117124
}
118125

119126
// Safety measure
120127
if !pm.IsManagedPlatformRelease(platformRelease) {
121-
return fmt.Errorf(tr("%s is not managed by package manager"), platformRelease)
128+
err := fmt.Errorf(tr("%s is not managed by package manager"), platformRelease)
129+
log.WithError(err).Error("Error uninstalling")
130+
return &arduino.FailedUninstallError{Message: err.Error()}
122131
}
123132

124133
if err := platformRelease.InstallDir.RemoveAll(); err != nil {
125-
return fmt.Errorf(tr("removing platform files: %s"), err)
134+
err = fmt.Errorf(tr("removing platform files: %s"), err)
135+
log.WithError(err).Error("Error uninstalling")
136+
return &arduino.FailedUninstallError{Message: err.Error()}
126137
}
138+
127139
platformRelease.InstallDir = nil
140+
141+
log.Info("Platform uninstalled")
142+
taskCB(&rpc.TaskProgress{Message: tr("Platform %s uninstalled", platformRelease), Completed: true})
128143
return nil
129144
}
130145

commands/core/install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ func installPlatform(pm *packagemanager.PackageManager,
145145

146146
// If upgrading remove previous release
147147
if installed != nil {
148-
uninstallErr := pm.UninstallPlatform(installed)
148+
uninstallErr := pm.UninstallPlatform(installed, taskCB)
149149

150150
// In case of error try to rollback
151151
if uninstallErr != nil {
152152
log.WithError(uninstallErr).Error("Error upgrading platform.")
153153
taskCB(&rpc.TaskProgress{Message: tr("Error upgrading platform: %s", uninstallErr)})
154154

155155
// Rollback
156-
if err := pm.UninstallPlatform(platformRelease); err != nil {
156+
if err := pm.UninstallPlatform(platformRelease, taskCB); err != nil {
157157
log.WithError(err).Error("Error rolling-back changes.")
158158
taskCB(&rpc.TaskProgress{Message: tr("Error rolling-back changes: %s", err)})
159159
}

commands/core/uninstall.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"context"
2020

2121
"github.com/arduino/arduino-cli/arduino"
22-
"github.com/arduino/arduino-cli/arduino/cores"
2322
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2423
"github.com/arduino/arduino-cli/commands"
2524
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -53,7 +52,7 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
5352
return nil, &arduino.NotFoundError{Message: tr("Can't find dependencies for platform %s", ref), Cause: err}
5453
}
5554

56-
if err := uninstallPlatformRelease(pm, platform, taskCB); err != nil {
55+
if err := pm.UninstallPlatform(platform, taskCB); err != nil {
5756
return nil, err
5857
}
5958

@@ -70,19 +69,3 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
7069

7170
return &rpc.PlatformUninstallResponse{}, nil
7271
}
73-
74-
func uninstallPlatformRelease(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, taskCB rpc.TaskProgressCB) error {
75-
log := pm.Log.WithField("platform", platformRelease)
76-
77-
log.Info("Uninstalling platform")
78-
taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", platformRelease)})
79-
80-
if err := pm.UninstallPlatform(platformRelease); err != nil {
81-
log.WithError(err).Error("Error uninstalling")
82-
return &arduino.FailedUninstallError{Message: tr("Error uninstalling platform %s", platformRelease), Cause: err}
83-
}
84-
85-
log.Info("Platform uninstalled")
86-
taskCB(&rpc.TaskProgress{Message: tr("Platform %s uninstalled", platformRelease), Completed: true})
87-
return nil
88-
}

commands/instances.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,15 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeRequest, downloadCB rpc.Downlo
772772
}
773773

774774
// Uninstall previously installed release
775-
err = pm.UninstallPlatform(installedRelease)
775+
err = pm.UninstallPlatform(installedRelease, taskCB)
776776

777777
// In case uninstall fails tries to rollback
778778
if err != nil {
779779
logrus.WithError(err).Error("Error updating platform.")
780780
taskCB(&rpc.TaskProgress{Message: tr("Error upgrading platform: %s", err)})
781781

782782
// Rollback
783-
if err := pm.UninstallPlatform(latest); err != nil {
783+
if err := pm.UninstallPlatform(latest, taskCB); err != nil {
784784
logrus.WithError(err).Error("Error rolling-back changes.")
785785
msg := tr("Error rolling-back changes")
786786
taskCB(&rpc.TaskProgress{Message: fmt.Sprintf("%s: %s", msg, err)})

0 commit comments

Comments
 (0)