@@ -48,6 +48,18 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
4848 return nil , err
4949 }
5050
51+ // update the local library_index if it is older than a certain threshold, to ensure the library is found when added by the arduino-cli
52+ stream , res := commands .UpdateLibrariesIndexStreamResponseToCallbackFunction (ctx , func (curr * rpc.DownloadProgress ) {
53+ // TODO: show log progres ?
54+ slog .Debug ("downloading library index" , "progress" , curr .Message )
55+ })
56+ req := & rpc.UpdateLibrariesIndexRequest {Instance : inst , UpdateIfOlderThanSecs : int64 (indexUpdateInterval .Seconds ())}
57+ if err := srv .UpdateLibrariesIndex (req , stream ); err != nil {
58+ //TODO: only print a warn message instead of failing ?? The local-library could contain the lib even if the update fail
59+ return []LibraryReleaseID {}, fmt .Errorf ("error updating library index: %v" , err )
60+ }
61+ slog .Debug ("Library index update" , "status" , res ().GetLibrariesIndex ().GetStatus ())
62+
5163 resp , err := srv .ProfileLibAdd (ctx , & rpc.ProfileLibAddRequest {
5264 Instance : inst ,
5365 SketchPath : app .MainSketchPath .String (),
@@ -65,18 +77,6 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
6577 return nil , err
6678 }
6779
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-
8080 return f .Map (resp .GetAddedLibraries (), rpcProfileLibReferenceToLibReleaseID ), nil
8181}
8282
0 commit comments