@@ -116,7 +116,7 @@ func (c *Cache) configure(options ...Option) {
116
116
c .watch .setup (c .specDirs , c .dirErrors )
117
117
c .watch .start (& c .Mutex , c .refresh , c .dirErrors )
118
118
}
119
- c .refresh ()
119
+ _ = c .refresh () // we record but ignore errors
120
120
}
121
121
122
122
// Refresh rescans the CDI Spec directories and refreshes the Cache.
@@ -222,7 +222,8 @@ func (c *Cache) refreshIfRequired(force bool) (bool, error) {
222
222
223
223
// InjectDevices injects the given qualified devices to an OCI Spec. It
224
224
// 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().
226
227
func (c * Cache ) InjectDevices (ociSpec * oci.Spec , devices ... string ) ([]string , error ) {
227
228
var unresolved []string
228
229
@@ -233,7 +234,7 @@ func (c *Cache) InjectDevices(ociSpec *oci.Spec, devices ...string) ([]string, e
233
234
c .Lock ()
234
235
defer c .Unlock ()
235
236
236
- c .refreshIfRequired (false )
237
+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
237
238
238
239
edits := & ContainerEdits {}
239
240
specs := map [* Spec ]struct {}{}
@@ -335,24 +336,27 @@ func (c *Cache) RemoveSpec(name string) error {
335
336
return err
336
337
}
337
338
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().
339
342
func (c * Cache ) GetDevice (device string ) * Device {
340
343
c .Lock ()
341
344
defer c .Unlock ()
342
345
343
- c .refreshIfRequired (false )
346
+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
344
347
345
348
return c .devices [device ]
346
349
}
347
350
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().
349
353
func (c * Cache ) ListDevices () []string {
350
354
var devices []string
351
355
352
356
c .Lock ()
353
357
defer c .Unlock ()
354
358
355
- c .refreshIfRequired (false )
359
+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
356
360
357
361
for name := range c .devices {
358
362
devices = append (devices , name )
@@ -362,14 +366,15 @@ func (c *Cache) ListDevices() []string {
362
366
return devices
363
367
}
364
368
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().
366
371
func (c * Cache ) ListVendors () []string {
367
372
var vendors []string
368
373
369
374
c .Lock ()
370
375
defer c .Unlock ()
371
376
372
- c .refreshIfRequired (false )
377
+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
373
378
374
379
for vendor := range c .specs {
375
380
vendors = append (vendors , vendor )
@@ -379,7 +384,8 @@ func (c *Cache) ListVendors() []string {
379
384
return vendors
380
385
}
381
386
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().
383
389
func (c * Cache ) ListClasses () []string {
384
390
var (
385
391
cmap = map [string ]struct {}{}
@@ -389,7 +395,7 @@ func (c *Cache) ListClasses() []string {
389
395
c .Lock ()
390
396
defer c .Unlock ()
391
397
392
- c .refreshIfRequired (false )
398
+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
393
399
394
400
for _ , specs := range c .specs {
395
401
for _ , spec := range specs {
@@ -404,12 +410,13 @@ func (c *Cache) ListClasses() []string {
404
410
return classes
405
411
}
406
412
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().
408
415
func (c * Cache ) GetVendorSpecs (vendor string ) []* Spec {
409
416
c .Lock ()
410
417
defer c .Unlock ()
411
418
412
- c .refreshIfRequired (false )
419
+ _ , _ = c .refreshIfRequired (false ) // we record but ignore errors
413
420
414
421
return c .specs [vendor ]
415
422
}
@@ -544,7 +551,7 @@ func (w *watch) watch(fsw *fsnotify.Watcher, m *sync.Mutex, refresh func() error
544
551
} else {
545
552
w .update (dirErrors )
546
553
}
547
- refresh ()
554
+ _ = refresh ()
548
555
m .Unlock ()
549
556
550
557
case _ , ok := <- watch .Errors :
0 commit comments