@@ -23,7 +23,6 @@ import (
23
23
"strings"
24
24
"time"
25
25
26
- "github.com/arduino/arduino-cli/cli/errorcodes"
27
26
"github.com/arduino/arduino-cli/commands"
28
27
"github.com/arduino/arduino-cli/commands/lib"
29
28
"github.com/arduino/arduino-cli/configuration"
@@ -53,7 +52,7 @@ func initSearchCommand() *cobra.Command {
53
52
}
54
53
55
54
// indexUpdateInterval specifies the time threshold over which indexes are updated
56
- const indexUpdateInterval = "60m"
55
+ const indexUpdateInterval = 60 * time . Minute
57
56
58
57
func runSearchCommand (args []string , namesOnly bool ) {
59
58
inst , status := instance .Create ()
@@ -190,12 +189,8 @@ func versionsFromSearchedLibrary(library *rpc.SearchedLibrary) []*semver.Version
190
189
return res
191
190
}
192
191
193
- // indexNeedsUpdating returns whether library_index.json need updating.
194
- // A positive duration string must be provided to calculate the time threshold
195
- // used to update the index.
196
- // Valid duration units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
197
- // Use a duration of 0 to always update the index.
198
- func indexNeedsUpdating (duration string ) bool {
192
+ // indexNeedsUpdating returns whether library_index.json needs updating
193
+ func indexNeedsUpdating (timeout time.Duration ) bool {
199
194
// Library index path is constant (relative to the data directory).
200
195
// It does not depend on board manager URLs or any other configuration.
201
196
dataDir := configuration .Settings .GetString ("directories.Data" )
@@ -208,19 +203,5 @@ func indexNeedsUpdating(duration string) bool {
208
203
if err != nil {
209
204
return true
210
205
}
211
- // Sanity check the given threshold duration string.
212
- now := time .Now ()
213
- modTimeThreshold , err := time .ParseDuration (duration )
214
- if err != nil {
215
- feedback .Error (tr ("Invalid timeout: %s" , err ))
216
- os .Exit (errorcodes .ErrBadArgument )
217
- }
218
- // The behavior of now.After(T) is confusing if T < 0 and MTIME in the future,
219
- // and is probably not what the user intended. Disallow negative T and inform
220
- // the user that positive thresholds are expected.
221
- if modTimeThreshold < 0 {
222
- feedback .Error (tr ("Timeout must be non-negative: %dns (%s)" , modTimeThreshold , duration ))
223
- os .Exit (errorcodes .ErrBadArgument )
224
- }
225
- return modTimeThreshold == 0 || now .After (info .ModTime ().Add (modTimeThreshold ))
206
+ return time .Since (info .ModTime ()) > timeout
226
207
}
0 commit comments