Skip to content

Commit f8679ad

Browse files
Simplify code applying minor changes
1 parent a7d7934 commit f8679ad

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

internal/cli/lib/search.go

+3-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"strings"
2424
"time"
2525

26-
"github.com/arduino/arduino-cli/cli/errorcodes"
2726
"github.com/arduino/arduino-cli/commands"
2827
"github.com/arduino/arduino-cli/commands/lib"
2928
"github.com/arduino/arduino-cli/configuration"
@@ -53,7 +52,7 @@ func initSearchCommand() *cobra.Command {
5352
}
5453

5554
// indexUpdateInterval specifies the time threshold over which indexes are updated
56-
const indexUpdateInterval = "60m"
55+
const indexUpdateInterval = 60 * time.Minute
5756

5857
func runSearchCommand(args []string, namesOnly bool) {
5958
inst, status := instance.Create()
@@ -193,9 +192,7 @@ func versionsFromSearchedLibrary(library *rpc.SearchedLibrary) []*semver.Version
193192
// indexNeedsUpdating returns whether library_index.json need updating.
194193
// A positive duration string must be provided to calculate the time threshold
195194
// 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 {
199196
// Library index path is constant (relative to the data directory).
200197
// It does not depend on board manager URLs or any other configuration.
201198
dataDir := configuration.Settings.GetString("directories.Data")
@@ -208,19 +205,5 @@ func indexNeedsUpdating(duration string) bool {
208205
if err != nil {
209206
return true
210207
}
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
226209
}

0 commit comments

Comments
 (0)