Skip to content

Commit 9ac0936

Browse files
committed
Rescan is called automatically after state-changing operations
1 parent 0f4666e commit 9ac0936

File tree

4 files changed

+45
-37
lines changed

4 files changed

+45
-37
lines changed

commands/core/install.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq, progress
3737
return nil, err
3838
}
3939

40+
_, err = commands.Rescan(ctx, &rpc.RescanReq{Instance: req.Instance})
41+
if err != nil {
42+
return nil, err
43+
}
44+
4045
return &rpc.PlatformInstallResp{}, nil
4146
}
4247

commands/core/uninstall.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq) (*rpc
7676
uninstallToolRelease(pm, tool)
7777
}
7878
}
79+
80+
_, err = commands.Rescan(ctx, &rpc.RescanReq{Instance: req.Instance})
81+
if err != nil {
82+
return nil, err
83+
}
7984
return &rpc.PlatformUninstallResp{}, nil
8085
}
8186

commands/core/upgrade.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq, progress
4848
if err != nil {
4949
return nil, err
5050
}
51+
52+
_, err = commands.Rescan(ctx, &rpc.RescanReq{Instance: req.Instance})
53+
if err != nil {
54+
return nil, err
55+
}
56+
5157
return &rpc.PlatformUpgradeResp{}, nil
5258
}
5359

daemon/client/client.go

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,7 @@ func main() {
3434
}
3535
instance := resp.GetInstance()
3636
fmt.Println("Created new server instance:", instance)
37-
UninstalResp, err := client.PlatformUninstall(context.Background(), &rpc.PlatformUninstallReq{
38-
Instance: instance,
39-
PlatformPackage: "arduino",
40-
Architecture: "samd",
41-
Version: "1.6.21",
42-
})
43-
if err != nil {
44-
if UninstalResp != nil {
45-
}
46-
fmt.Printf("uninstall error: %s\n", err)
47-
os.Exit(1)
48-
}
37+
4938
install := func() {
5039
installRespStream, err := client.PlatformInstall(context.Background(), &rpc.PlatformInstallReq{
5140
Instance: instance,
@@ -64,45 +53,37 @@ func main() {
6453
}
6554
if err != nil {
6655
fmt.Printf("Install error: %s\n", err)
67-
os.Exit(1)
56+
return
6857
}
6958
fmt.Printf("%s\n", installResp.GetProgress())
7059
}
7160
fmt.Println("Installation completed!")
7261
}
62+
7363
install()
74-
respResc, err := client.Rescan(context.Background(), &rpc.RescanReq{
75-
Instance: instance,
64+
install()
65+
66+
upgradeRespStream, err := client.PlatformUpgrade(context.Background(), &rpc.PlatformUpgradeReq{
67+
Instance: instance,
68+
PlatformPackage: "arduino",
69+
Architecture: "samd",
7670
})
7771
if err != nil {
78-
fmt.Printf("Error creating server instance: %s\n", err)
72+
fmt.Printf("Error Upgrade platform: %s\n", err)
7973
os.Exit(1)
8074
}
81-
instance = respResc.GetInstance()
82-
upgrade := func() {
83-
upgradeRespStream, err := client.PlatformUpgrade(context.Background(), &rpc.PlatformUpgradeReq{
84-
Instance: instance,
85-
PlatformPackage: "arduino",
86-
Architecture: "samd",
87-
})
75+
for {
76+
upgradeResp, err := upgradeRespStream.Recv()
77+
if err == io.EOF {
78+
break
79+
}
8880
if err != nil {
89-
fmt.Printf("Error Upgrade platform: %s\n", err)
81+
fmt.Printf("Upgrade error: %s\n", err)
9082
os.Exit(1)
9183
}
92-
for {
93-
upgradeResp, err := upgradeRespStream.Recv()
94-
if err == io.EOF {
95-
break
96-
}
97-
if err != nil {
98-
fmt.Printf("Install error: %s\n", err)
99-
os.Exit(1)
100-
}
101-
fmt.Printf("%s\n", upgradeResp.GetProgress())
102-
}
103-
fmt.Println("Upgrade completed!")
84+
fmt.Printf("%s\n", upgradeResp.GetProgress())
10485
}
105-
upgrade()
86+
fmt.Println("Upgrade completed!")
10687

10788
details, err := client.BoardDetails(context.Background(), &rpc.BoardDetailsReq{
10889
Instance: instance,
@@ -153,6 +134,17 @@ func main() {
153134
}
154135
*/
155136

137+
_, err = client.PlatformUninstall(context.Background(), &rpc.PlatformUninstallReq{
138+
Instance: instance,
139+
PlatformPackage: "arduino",
140+
Architecture: "samd",
141+
Version: "1.6.21",
142+
})
143+
if err != nil {
144+
fmt.Printf("uninstall error: %s\n", err)
145+
// os.Exit(1)
146+
}
147+
156148
_, err = client.Destroy(context.Background(), &rpc.DestroyReq{
157149
Instance: instance,
158150
})

0 commit comments

Comments
 (0)