@@ -362,7 +362,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
362362 // Create the new snapshot dir
363363 snDir := s .getSnapshotDir (newSnapshot .ID )
364364 if err = os .MkdirAll (snDir , 0700 ); err != nil {
365- return err
365+ return fmt . Errorf ( "creating snapshot dir: %w" , err )
366366 }
367367
368368 if strings .Contains (key , snapshots .UnpackKeyPrefix ) {
@@ -372,57 +372,59 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
372372 // snapshot if this isn't the snapshot that just houses the final sandbox.vhd
373373 // that will be mounted as the containers scratch. Currently the key for a snapshot
374374 // where a layer will be extracted to will have the string `extract-` in it.
375- } else if len (newSnapshot .ParentIDs ) == 0 {
375+ return nil
376+ }
377+
378+ if len (newSnapshot .ParentIDs ) == 0 {
376379 // A parentless snapshot is just a bind-mount to a directory named
377380 // "Files". When committed, there'll be some post-processing to fill in the rest
378381 // of the metadata.
379382 filesDir := filepath .Join (snDir , "Files" )
380383 if err := os .MkdirAll (filesDir , 0700 ); err != nil {
381- return err
384+ return fmt . Errorf ( "creating Files dir: %w" , err )
382385 }
383- } else {
384- parentLayerPaths := s . parentIDsToParentPaths ( newSnapshot . ParentIDs )
386+ return nil
387+ }
385388
386- var snapshotInfo snapshots.Info
387- for _ , o := range opts {
388- o (& snapshotInfo )
389- }
389+ parentLayerPaths := s .parentIDsToParentPaths (newSnapshot .ParentIDs )
390+ var snapshotInfo snapshots.Info
391+ for _ , o := range opts {
392+ o (& snapshotInfo )
393+ }
390394
391- var sizeInBytes uint64
392- if sizeGBstr , ok := snapshotInfo .Labels [rootfsSizeInGBLabel ]; ok {
393- log .G (ctx ).Warnf ("%q label is deprecated, please use %q instead." , rootfsSizeInGBLabel , rootfsSizeInBytesLabel )
395+ var sizeInBytes uint64
396+ if sizeGBstr , ok := snapshotInfo .Labels [rootfsSizeInGBLabel ]; ok {
397+ log .G (ctx ).Warnf ("%q label is deprecated, please use %q instead." , rootfsSizeInGBLabel , rootfsSizeInBytesLabel )
394398
395- sizeInGB , err := strconv .ParseUint (sizeGBstr , 10 , 32 )
396- if err != nil {
397- return fmt .Errorf ("failed to parse label %q=%q: %w" , rootfsSizeInGBLabel , sizeGBstr , err )
398- }
399- sizeInBytes = sizeInGB * 1024 * 1024 * 1024
399+ sizeInGB , err := strconv .ParseUint (sizeGBstr , 10 , 32 )
400+ if err != nil {
401+ return fmt .Errorf ("failed to parse label %q=%q: %w" , rootfsSizeInGBLabel , sizeGBstr , err )
400402 }
403+ sizeInBytes = sizeInGB * 1024 * 1024 * 1024
404+ }
401405
402- // Prefer the newer label in bytes over the deprecated Windows specific GB variant.
403- if sizeBytesStr , ok := snapshotInfo .Labels [rootfsSizeInBytesLabel ]; ok {
404- sizeInBytes , err = strconv .ParseUint (sizeBytesStr , 10 , 64 )
405- if err != nil {
406- return fmt .Errorf ("failed to parse label %q=%q: %w" , rootfsSizeInBytesLabel , sizeBytesStr , err )
407- }
406+ // Prefer the newer label in bytes over the deprecated Windows specific GB variant.
407+ if sizeBytesStr , ok := snapshotInfo .Labels [rootfsSizeInBytesLabel ]; ok {
408+ sizeInBytes , err = strconv .ParseUint (sizeBytesStr , 10 , 64 )
409+ if err != nil {
410+ return fmt .Errorf ("failed to parse label %q=%q: %w" , rootfsSizeInBytesLabel , sizeBytesStr , err )
408411 }
412+ }
409413
410- var makeUVMScratch bool
411- if _ , ok := snapshotInfo .Labels [uvmScratchLabel ]; ok {
412- makeUVMScratch = true
413- }
414+ var makeUVMScratch bool
415+ if _ , ok := snapshotInfo .Labels [uvmScratchLabel ]; ok {
416+ makeUVMScratch = true
417+ }
414418
415- // This has to be run first to avoid clashing with the containers sandbox.vhdx.
416- if makeUVMScratch {
417- if err = s .createUVMScratchLayer (ctx , snDir , parentLayerPaths ); err != nil {
418- return fmt .Errorf ("failed to make UVM's scratch layer: %w" , err )
419- }
420- }
421- if err = s .createScratchLayer (ctx , snDir , parentLayerPaths , sizeInBytes ); err != nil {
422- return fmt .Errorf ("failed to create scratch layer: %w" , err )
419+ // This has to be run first to avoid clashing with the containers sandbox.vhdx.
420+ if makeUVMScratch {
421+ if err = s .createUVMScratchLayer (ctx , snDir , parentLayerPaths ); err != nil {
422+ return fmt .Errorf ("failed to make UVM's scratch layer: %w" , err )
423423 }
424424 }
425-
425+ if err = s .createScratchLayer (ctx , snDir , parentLayerPaths , sizeInBytes ); err != nil {
426+ return fmt .Errorf ("failed to create scratch layer: %w" , err )
427+ }
426428 return nil
427429 })
428430 if err != nil {
0 commit comments