Skip to content

Commit 6c89894

Browse files
Simplify code applying minor changes
1 parent a7d7934 commit 6c89894

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

internal/cli/lib/search.go

+4-23
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()
@@ -190,12 +189,8 @@ func versionsFromSearchedLibrary(library *rpc.SearchedLibrary) []*semver.Version
190189
return res
191190
}
192191

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 {
199194
// Library index path is constant (relative to the data directory).
200195
// It does not depend on board manager URLs or any other configuration.
201196
dataDir := configuration.Settings.GetString("directories.Data")
@@ -208,19 +203,5 @@ func indexNeedsUpdating(duration string) bool {
208203
if err != nil {
209204
return true
210205
}
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
226207
}

0 commit comments

Comments
 (0)