Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC: added CleanDownloadCacheDirectory rpc call #2572

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions commands/cache/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of arduino-cli.
//
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package cache

import (
"context"

"github.com/arduino/arduino-cli/internal/cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

// CleanDownloadCacheDirectory clean the download cache directory (where archives are downloaded).
func CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
cachePath := configuration.DownloadsDir(configuration.Settings)
err := cachePath.RemoveAll()
if err != nil {
return nil, err
}
return &rpc.CleanDownloadCacheDirectoryResponse{}, nil
}
7 changes: 7 additions & 0 deletions commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/commands/cache"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/commands/core"
Expand Down Expand Up @@ -581,3 +582,9 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
}
return nil
}

// CleanDownloadCacheDirectory FIXMEDOC
func (s *ArduinoCoreServerImpl) CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
resp, err := cache.CleanDownloadCacheDirectory(ctx, req)
return resp, convertErrorToRPCStatus(err)
}
7 changes: 4 additions & 3 deletions internal/cli/cache/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package cache

import (
"context"
"os"

"github.com/arduino/arduino-cli/internal/cli/configuration"
"github.com/arduino/arduino-cli/commands/cache"
"github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -39,8 +41,7 @@ func initCleanCommand() *cobra.Command {
func runCleanCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino-cli cache clean`")

cachePath := configuration.DownloadsDir(configuration.Settings)
err := cachePath.RemoveAll()
_, err := cache.CleanDownloadCacheDirectory(context.Background(), &rpc.CleanDownloadCacheDirectoryRequest{})
if err != nil {
feedback.Fatal(tr("Error cleaning caches: %v", err), feedback.ErrGeneric)
}
Expand Down
Loading
Loading