@@ -26,18 +26,37 @@ import (
26
26
)
27
27
28
28
// 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
+ }
31
43
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 {
32
51
pme , release := commands .GetPackageManagerExplorer (req )
33
52
if pme == nil {
34
- return nil , & arduino.InvalidInstanceError {}
53
+ return & arduino.InvalidInstanceError {}
35
54
}
36
55
defer release ()
37
56
38
57
version , err := commands .ParseVersion (req )
39
58
if err != nil {
40
- return nil , & arduino.InvalidVersionError {Cause : err }
59
+ return & arduino.InvalidVersionError {Cause : err }
41
60
}
42
61
43
62
ref := & packagemanager.PlatformReference {
@@ -47,30 +66,26 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
47
66
}
48
67
platformRelease , tools , err := pme .FindPlatformReleaseDependencies (ref )
49
68
if err != nil {
50
- return nil , & arduino.PlatformNotFoundError {Platform : ref .String (), Cause : err }
69
+ return & arduino.PlatformNotFoundError {Platform : ref .String (), Cause : err }
51
70
}
52
71
53
72
// Prerequisite checks before install
54
73
if platformRelease .IsInstalled () {
55
74
taskCB (& rpc.TaskProgress {Name : tr ("Platform %s already installed" , platformRelease ), Completed : true })
56
- return & rpc. PlatformInstallResponse {}, nil
75
+ return nil
57
76
}
58
77
59
78
if req .GetNoOverwrite () {
60
79
if installed := pme .GetInstalledPlatformRelease (platformRelease .Platform ); installed != nil {
61
- return nil , fmt .Errorf ("%s: %s" ,
80
+ return fmt .Errorf ("%s: %s" ,
62
81
tr ("Platform %s already installed" , installed ),
63
82
tr ("could not overwrite" ))
64
83
}
65
84
}
66
85
67
86
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
73
88
}
74
89
75
- return & rpc. PlatformInstallResponse {}, nil
90
+ return nil
76
91
}
0 commit comments