Skip to content

Commit bebdcce

Browse files
committed
gRPC: added CleanDownloadCacheDirectory rpc call
1 parent 67d2c57 commit bebdcce

File tree

6 files changed

+743
-518
lines changed

6 files changed

+743
-518
lines changed

Diff for: commands/cache/clean.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package cache
17+
18+
import (
19+
"context"
20+
21+
"github.com/arduino/arduino-cli/internal/cli/configuration"
22+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
23+
)
24+
25+
// CleanDownloadCacheDirectory clean the download cache directory (where archives are downloaded).
26+
func CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
27+
cachePath := configuration.DownloadsDir(configuration.Settings)
28+
err := cachePath.RemoveAll()
29+
if err != nil {
30+
return nil, err
31+
}
32+
return &rpc.CleanDownloadCacheDirectoryResponse{}, nil
33+
}

Diff for: commands/daemon/daemon.go

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/arduino/arduino-cli/commands"
2626
"github.com/arduino/arduino-cli/commands/board"
27+
"github.com/arduino/arduino-cli/commands/cache"
2728
"github.com/arduino/arduino-cli/commands/cmderrors"
2829
"github.com/arduino/arduino-cli/commands/compile"
2930
"github.com/arduino/arduino-cli/commands/core"
@@ -581,3 +582,9 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
581582
}
582583
return nil
583584
}
585+
586+
// CleanDownloadCacheDirectory FIXMEDOC
587+
func (s *ArduinoCoreServerImpl) CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
588+
resp, err := cache.CleanDownloadCacheDirectory(ctx, req)
589+
return resp, convertErrorToRPCStatus(err)
590+
}

Diff for: internal/cli/cache/clean.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
package cache
1717

1818
import (
19+
"context"
1920
"os"
2021

21-
"github.com/arduino/arduino-cli/internal/cli/configuration"
22+
"github.com/arduino/arduino-cli/commands/cache"
2223
"github.com/arduino/arduino-cli/internal/cli/feedback"
24+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2325
"github.com/sirupsen/logrus"
2426
"github.com/spf13/cobra"
2527
)
@@ -39,8 +41,7 @@ func initCleanCommand() *cobra.Command {
3941
func runCleanCommand(cmd *cobra.Command, args []string) {
4042
logrus.Info("Executing `arduino-cli cache clean`")
4143

42-
cachePath := configuration.DownloadsDir(configuration.Settings)
43-
err := cachePath.RemoveAll()
44+
_, err := cache.CleanDownloadCacheDirectory(context.Background(), &rpc.CleanDownloadCacheDirectoryRequest{})
4445
if err != nil {
4546
feedback.Fatal(tr("Error cleaning caches: %v", err), feedback.ErrGeneric)
4647
}

0 commit comments

Comments
 (0)