@@ -17,6 +17,9 @@ package orchestrator
1717
1818import (
1919 "context"
20+ "fmt"
21+ "log/slog"
22+ "time"
2023
2124 "github.com/arduino/arduino-cli/commands"
2225 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -25,6 +28,8 @@ import (
2528 "github.com/arduino/arduino-app-cli/internal/orchestrator/app"
2629)
2730
31+ const indexUpdateInterval = 1 * time .Second // TODO change to a better value
32+
2833func AddSketchLibrary (ctx context.Context , app app.ArduinoApp , libRef LibraryReleaseID , addDeps bool ) ([]LibraryReleaseID , error ) {
2934 srv := commands .NewArduinoCoreServer ()
3035 var inst * rpc.Instance
@@ -59,6 +64,19 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
5964 if err != nil {
6065 return nil , err
6166 }
67+
68+ // since the local library-index could be outofdate with respect the public library index, w
69+ stream , res := commands .UpdateLibrariesIndexStreamResponseToCallbackFunction (ctx , func (curr * rpc.DownloadProgress ) {
70+ // TODO: LOG progress ?
71+ slog .Error ("progress" , "msg" , curr .String ())
72+ })
73+ req := & rpc.UpdateLibrariesIndexRequest {Instance : inst , UpdateIfOlderThanSecs : int64 (indexUpdateInterval )}
74+ if err := srv .UpdateLibrariesIndex (req , stream ); err != nil {
75+ // TODO: is it correct to step the add of a library even is the library index could not be updated ?
76+ return []LibraryReleaseID {}, fmt .Errorf ("error updating library index: %v" , err )
77+ }
78+ slog .Error ("OOOK Library index update" , "index" , res ().GetLibrariesIndex ())
79+
6280 return f .Map (resp .GetAddedLibraries (), rpcProfileLibReferenceToLibReleaseID ), nil
6381}
6482
0 commit comments