Skip to content

Commit 5a33829

Browse files
dido18lucarin91
andauthored
fix: install a library missing from local library-index (#50)
* feat: enhance AddSketchLibrary to update library index and log progress * fix: improve library index update handling in AddSketchLibrary * fix: improve error handling in AddSketchLibrary by logging warnings instead of failing on library index update * fix: extend library index update interval to 60 seconds for improved performance * fix: update library index refresh interval to 10 minutes for improved performance * fix: improve error handling in AddSketchLibrary by logging warnings for library index update failures * Update internal/orchestrator/sketch_libs.go Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc> * Update internal/orchestrator/sketch_libs.go Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc> --------- Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc>
1 parent c64fbf6 commit 5a33829

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/orchestrator/sketch_libs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package orchestrator
1717

1818
import (
1919
"context"
20+
"log/slog"
21+
"time"
2022

2123
"github.com/arduino/arduino-cli/commands"
2224
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -25,6 +27,8 @@ import (
2527
"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
2628
)
2729

30+
const indexUpdateInterval = 10 * time.Minute
31+
2832
func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryReleaseID, addDeps bool) ([]LibraryReleaseID, error) {
2933
srv := commands.NewArduinoCoreServer()
3034
var inst *rpc.Instance
@@ -43,6 +47,15 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
4347
return nil, err
4448
}
4549

50+
stream, _ := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) {
51+
slog.Debug("downloading library index", "progress", curr.GetMessage())
52+
})
53+
// update the local library index after a certain time, to avoid if a library is added to the sketch but the local library index is not update, the compile can fail (because the lib is not found)
54+
req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())}
55+
if err := srv.UpdateLibrariesIndex(req, stream); err != nil {
56+
slog.Warn("error updating library index, skipping", slog.String("error", err.Error()))
57+
}
58+
4659
resp, err := srv.ProfileLibAdd(ctx, &rpc.ProfileLibAddRequest{
4760
Instance: inst,
4861
SketchPath: app.MainSketchPath.String(),
@@ -59,6 +72,7 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
5972
if err != nil {
6073
return nil, err
6174
}
75+
6276
return f.Map(resp.GetAddedLibraries(), rpcProfileLibReferenceToLibReleaseID), nil
6377
}
6478

0 commit comments

Comments
 (0)