@@ -116,7 +116,7 @@ func (c *Cache) configure(options ...Option) {
116116 c .watch .setup (c .specDirs , c .dirErrors )
117117 c .watch .start (& c .Mutex , c .refresh , c .dirErrors )
118118 }
119- c .refresh ()
119+ _ = c .refresh () // we record but ignore errors
120120}
121121
122122// Refresh rescans the CDI Spec directories and refreshes the Cache.
@@ -222,7 +222,8 @@ func (c *Cache) refreshIfRequired(force bool) (bool, error) {
222222
223223// InjectDevices injects the given qualified devices to an OCI Spec. It
224224// returns any unresolvable devices and an error if injection fails for
225- // any of the devices.
225+ // any of the devices. Might trigger a cache refresh, in which case any
226+ // errors encountered can be obtained using GetErrors().
226227func (c * Cache ) InjectDevices (ociSpec * oci.Spec , devices ... string ) ([]string , error ) {
227228 var unresolved []string
228229
@@ -233,7 +234,7 @@ func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, e
233234 c .Lock ()
234235 defer c .Unlock ()
235236
236- c .refreshIfRequired (false )
237+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
237238
238239 edits := & ContainerEdits {}
239240 specs := map [* Spec ]struct {}{}
@@ -335,24 +336,27 @@ func (c *Cache) RemoveSpec(name string) error {
335336 return err
336337}
337338
338- // GetDevice returns the cached device for the given qualified name.
339+ // GetDevice returns the cached device for the given qualified name. Might trigger
340+ // a cache refresh, in which case any errors encountered can be obtained using
341+ // GetErrors().
339342func (c * Cache ) GetDevice (device string ) * Device {
340343 c .Lock ()
341344 defer c .Unlock ()
342345
343- c .refreshIfRequired (false )
346+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
344347
345348 return c .devices [device ]
346349}
347350
348- // ListDevices lists all cached devices by qualified name.
351+ // ListDevices lists all cached devices by qualified name. Might trigger a cache
352+ // refresh, in which case any errors encountered can be obtained using GetErrors().
349353func (c * Cache ) ListDevices () []string {
350354 var devices []string
351355
352356 c .Lock ()
353357 defer c .Unlock ()
354358
355- c .refreshIfRequired (false )
359+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
356360
357361 for name := range c .devices {
358362 devices = append (devices , name )
@@ -362,14 +366,15 @@ func (c *Cache) ListDevices() []string {
362366 return devices
363367}
364368
365- // ListVendors lists all vendors known to the cache.
369+ // ListVendors lists all vendors known to the cache. Might trigger a cache refresh,
370+ // in which case any errors encountered can be obtained using GetErrors().
366371func (c * Cache ) ListVendors () []string {
367372 var vendors []string
368373
369374 c .Lock ()
370375 defer c .Unlock ()
371376
372- c .refreshIfRequired (false )
377+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
373378
374379 for vendor := range c .specs {
375380 vendors = append (vendors , vendor )
@@ -379,7 +384,8 @@ func (c *Cache) ListVendors() []string {
379384 return vendors
380385}
381386
382- // ListClasses lists all device classes known to the cache.
387+ // ListClasses lists all device classes known to the cache. Might trigger a cache
388+ // refresh, in which case any errors encountered can be obtained using GetErrors().
383389func (c * Cache ) ListClasses () []string {
384390 var (
385391 cmap = map [string ]struct {}{}
@@ -389,7 +395,7 @@ func (c *Cache) ListClasses() []string {
389395 c .Lock ()
390396 defer c .Unlock ()
391397
392- c .refreshIfRequired (false )
398+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
393399
394400 for _ , specs := range c .specs {
395401 for _ , spec := range specs {
@@ -404,12 +410,13 @@ func (c *Cache) ListClasses() []string {
404410 return classes
405411}
406412
407- // GetVendorSpecs returns all specs for the given vendor.
413+ // GetVendorSpecs returns all specs for the given vendor. Might trigger a cache
414+ // refresh, in which case any errors encountered can be obtained using GetErrors().
408415func (c * Cache ) GetVendorSpecs (vendor string ) []* Spec {
409416 c .Lock ()
410417 defer c .Unlock ()
411418
412- c .refreshIfRequired (false )
419+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
413420
414421 return c .specs [vendor ]
415422}
@@ -544,7 +551,7 @@ func (w *watch) watch(fsw *fsnotify.Watcher, m *sync.Mutex, refresh func() error
544551 } else {
545552 w .update (dirErrors )
546553 }
547- refresh ()
554+ _ = refresh ()
548555 m .Unlock ()
549556
550557 case _ , ok := <- watch .Errors :
0 commit comments