@@ -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 ()
@@ -193,9 +192,7 @@ func versionsFromSearchedLibrary(library *rpc.SearchedLibrary) []*semver.Version
193
192
// indexNeedsUpdating returns whether library_index.json need updating.
194
193
// A positive duration string must be provided to calculate the time threshold
195
194
// 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 {
195
+ func indexNeedsUpdating (timeout time.Duration ) bool {
199
196
// Library index path is constant (relative to the data directory).
200
197
// It does not depend on board manager URLs or any other configuration.
201
198
dataDir := configuration .Settings .GetString ("directories.Data" )
@@ -208,19 +205,5 @@ func indexNeedsUpdating(duration string) bool {
208
205
if err != nil {
209
206
return true
210
207
}
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 ))
208
+ return time .Since (info .ModTime ()) > timeout
226
209
}
0 commit comments