87
87
errUnsupported = errors .New ("unsupported" )
88
88
errUser = errors .New ("user detection error" )
89
89
errWipe = errors .New ("device wipe error" )
90
+ errYAML = errors .New ("yaml retrieval error" )
90
91
91
92
// ErrLabel is made public to that callers can warn on mismatches.
92
93
ErrLabel = errors .New (`label error` )
@@ -120,6 +121,8 @@ type Configuration interface {
120
121
SeedFile () string
121
122
SeedServer () string
122
123
UpdateOnly () bool
124
+ ConfName () string
125
+ ConfPath () string
123
126
}
124
127
125
128
// Device represents storage.Device.
@@ -269,16 +272,30 @@ func (i *Installer) Retrieve() (err error) {
269
272
return i .retrieveFile (i .config .ImageFile (), i .config .Image ())
270
273
}
271
274
272
- // Check FFU Path configuration
275
+ // Check FFU Path configuration.
273
276
if i .config .FFUPath () == "" {
274
277
return fmt .Errorf ("missing FFU path: %w" , errConfig )
275
278
}
276
279
277
- // Check FFU Manifest configuration
280
+ // Check FFU Manifest configuration.
278
281
if i .config .FFUManifest () == "" {
279
282
return fmt .Errorf ("missing FFU manifest: %w" , errConfig )
280
283
}
281
284
285
+ // Check for missing conf file name.
286
+ if i .config .ConfName () == "" {
287
+ return fmt .Errorf ("missing configuration file name: %w" , errConfig )
288
+ }
289
+
290
+ // Check conf path configuration.
291
+ if i .config .ConfPath () == "" {
292
+ return fmt .Errorf ("missing conf file path: %w" , errConfig )
293
+ }
294
+
295
+ if err := i .retrieveFile (i .config .ConfName (), i .config .ConfPath ()); err != nil {
296
+ return fmt .Errorf ("%w: %v" , errYAML , err )
297
+ }
298
+
282
299
if err := i .retrieveFile (i .config .ImageFile (), i .config .Image ()); err != nil {
283
300
return fmt .Errorf ("%w: %v" , errImage , err )
284
301
}
@@ -475,7 +492,8 @@ func (i *Installer) DownloadSFU() error {
475
492
return nil
476
493
}
477
494
478
- // PlaceSFU copies SFU files onto provisioned media from the local cache.
495
+ // PlaceSFU copies SFU files and config files onto provisioned media
496
+ // from the local cache.
479
497
func (i * Installer ) PlaceSFU (d Device ) error {
480
498
// Find a compatible partition to write the FFU to.
481
499
logger .V (2 ).Infof ("Searching for FFU %q for a %q partition larger than %v." , d .FriendlyName (), humanize .Bytes (minSFUPartSize ), storage .FAT32 )
@@ -487,39 +505,46 @@ func (i *Installer) PlaceSFU(d Device) error {
487
505
if err != nil {
488
506
return fmt .Errorf ("getManifest() returned: %w: %v" , errManifest , err )
489
507
}
508
+ // Copy SFU files.
490
509
for ind , sfu := range sfus {
491
- // This is done as a separate function call to handle closing
492
- // the files through the defer at the end of each iteration
493
- // of the loop instead of waiting until the end of the function.
494
- func () error {
495
- path := filepath .Join (i .cache , sfu .Filename )
496
- newPath := filepath .Join (p .MountPoint (), i .config .FFUDest (), sfu .Filename )
497
- // Add colon for windows paths if its a drive root.
498
- if runtime .GOOS == "windows" && len (p .MountPoint ()) < 2 {
499
- newPath = filepath .Join (fmt .Sprintf ("%s:" , p .MountPoint ()), i .config .FFUDest (), sfu .Filename )
500
- }
501
- console .Printf ("Copying SFU %d of %d..." , ind + 1 , len (sfus ))
502
- if err := os .MkdirAll (filepath .Dir (newPath ), 0644 ); err != nil {
503
- return fmt .Errorf ("failed to create path: %v" , err )
504
- }
505
- source , err := os .Open (path )
506
- if err != nil {
507
- return fmt .Errorf ("%w: couldn't open file(%s) from cache: %v" , errPath , path , err )
508
- }
509
- defer source .Close ()
510
- destination , err := os .Create (newPath )
511
- if err != nil {
512
- return fmt .Errorf ("%w: couldn't create target file(%s): %v" , errFile , path , err )
513
- }
514
- defer destination .Close ()
515
- cBytes , err := io .Copy (destination , source )
516
- if err != nil {
517
- return fmt .Errorf ("failed to copy file to %s: %v" , newPath , err )
518
- }
519
- console .Printf ("Copied %d bytes" , cBytes )
520
- return nil
521
- }()
510
+ console .Printf ("Copying SFU %d of %d..." , ind + 1 , len (sfus ))
511
+ if err := i .fileCopy (sfu .Filename , i .config .FFUDest (), p ); err != nil {
512
+ return err
513
+ }
514
+ }
515
+ // Copy config.
516
+ console .Printf ("Copying %s" , i .config .ConfName ())
517
+ if err := i .fileCopy (i .config .ConfName (), i .config .FFUDest (), p ); err != nil {
518
+ return err
519
+ }
520
+ return nil
521
+ }
522
+
523
+ func (i * Installer ) fileCopy (file , dest string , p partition ) error {
524
+ path := filepath .Join (i .cache , file )
525
+ newPath := filepath .Join (p .MountPoint (), dest , file )
526
+ // Add colon for windows paths if its a drive root.
527
+ if runtime .GOOS == "windows" && len (p .MountPoint ()) < 2 {
528
+ newPath = filepath .Join (fmt .Sprintf ("%s:" , p .MountPoint ()), dest , file )
529
+ }
530
+ if err := os .MkdirAll (filepath .Dir (newPath ), 0644 ); err != nil {
531
+ return fmt .Errorf ("failed to create path: %v" , err )
532
+ }
533
+ source , err := os .Open (path )
534
+ if err != nil {
535
+ return fmt .Errorf ("%w: couldn't open file(%s) from cache: %v" , errPath , path , err )
536
+ }
537
+ defer source .Close ()
538
+ destination , err := os .Create (newPath )
539
+ if err != nil {
540
+ return fmt .Errorf ("%w: couldn't create target file(%s): %v" , errFile , path , err )
541
+ }
542
+ defer destination .Close ()
543
+ cBytes , err := io .Copy (destination , source )
544
+ if err != nil {
545
+ return fmt .Errorf ("failed to copy file to %s: %v" , newPath , err )
522
546
}
547
+ console .Printf ("Copied %d bytes" , cBytes )
523
548
return nil
524
549
}
525
550
0 commit comments