@@ -1452,7 +1452,16 @@ func (s *store) canUseShifting(uidmap, gidmap []idtools.IDMap) bool {
14521452// On entry:
14531453// - rlstore must be locked for writing
14541454// - rlstores MUST NOT be locked
1455- func (s * store ) putLayer (rlstore rwLayerStore , rlstores []roLayerStore , id , parent string , names []string , mountLabel string , writeable bool , lOptions * LayerOptions , slo * stagedLayerOptions ) (* Layer , int64 , error ) {
1455+ func (s * store ) putLayer (rlstore rwLayerStore , id string , parentLayer * Layer , names []string , mountLabel string , writeable bool , options * LayerOptions , slo * stagedLayerOptions ) (* Layer , int64 , error ) {
1456+ return rlstore .create (id , parentLayer , names , mountLabel , nil , options , writeable , slo )
1457+ }
1458+
1459+ // On entry:
1460+ // - rlstore must be locked for writing
1461+ // - rlstores MUST NOT be locked
1462+ //
1463+ // Returns the new copied LayerOptions with mappings set and the parent Layer.
1464+ func populateLayerOptions (s * store , rlstore rwLayerStore , rlstores []roLayerStore , parent string , lOptions * LayerOptions ) (* LayerOptions , * Layer , error ) {
14561465 var parentLayer * Layer
14571466 var options LayerOptions
14581467 if lOptions != nil {
@@ -1474,7 +1483,7 @@ func (s *store) putLayer(rlstore rwLayerStore, rlstores []roLayerStore, id, pare
14741483 lstore := l
14751484 if lstore != rlstore {
14761485 if err := lstore .startReading (); err != nil {
1477- return nil , - 1 , err
1486+ return nil , nil , err
14781487 }
14791488 defer lstore .stopReading ()
14801489 }
@@ -1485,21 +1494,21 @@ func (s *store) putLayer(rlstore rwLayerStore, rlstores []roLayerStore, id, pare
14851494 }
14861495 }
14871496 if ilayer == nil {
1488- return nil , - 1 , ErrLayerUnknown
1497+ return nil , nil , ErrLayerUnknown
14891498 }
14901499 parentLayer = ilayer
14911500
14921501 if err := s .containerStore .startWriting (); err != nil {
1493- return nil , - 1 , err
1502+ return nil , nil , err
14941503 }
14951504 defer s .containerStore .stopWriting ()
14961505 containers , err := s .containerStore .Containers ()
14971506 if err != nil {
1498- return nil , - 1 , err
1507+ return nil , nil , err
14991508 }
15001509 for _ , container := range containers {
15011510 if container .LayerID == parent {
1502- return nil , - 1 , ErrParentIsContainer
1511+ return nil , nil , ErrParentIsContainer
15031512 }
15041513 }
15051514 if ! options .HostUIDMapping && len (options .UIDMap ) == 0 {
@@ -1526,7 +1535,7 @@ func (s *store) putLayer(rlstore rwLayerStore, rlstores []roLayerStore, id, pare
15261535 GIDMap : copySlicePreferringNil (gidMap ),
15271536 }
15281537 }
1529- return rlstore . create ( id , parentLayer , names , mountLabel , nil , & options , writeable , slo )
1538+ return & options , parentLayer , nil
15301539}
15311540
15321541func (s * store ) PutLayer (id , parent string , names []string , mountLabel string , writeable bool , lOptions * LayerOptions , diff io.Reader ) (* Layer , int64 , error ) {
@@ -1557,7 +1566,12 @@ func (s *store) PutLayer(id, parent string, names []string, mountLabel string, w
15571566 return nil , - 1 , err
15581567 }
15591568 defer rlstore .stopWriting ()
1560- return s .putLayer (rlstore , rlstores , id , parent , names , mountLabel , writeable , lOptions , slo )
1569+
1570+ options , parentLayer , err := populateLayerOptions (s , rlstore , rlstores , parent , lOptions )
1571+ if err != nil {
1572+ return nil , - 1 , err
1573+ }
1574+ return s .putLayer (rlstore , id , parentLayer , names , mountLabel , writeable , options , slo )
15611575}
15621576
15631577func (s * store ) CreateLayer (id , parent string , names []string , mountLabel string , writeable bool , options * LayerOptions ) (* Layer , error ) {
@@ -3198,7 +3212,11 @@ func (s *store) ApplyStagedLayer(args ApplyStagedLayerOptions) (*Layer, error) {
31983212 DiffOutput : args .DiffOutput ,
31993213 DiffOptions : args .DiffOptions ,
32003214 }
3201- layer , _ , err = s .putLayer (rlstore , rlstores , args .ID , args .ParentLayer , args .Names , args .MountLabel , args .Writeable , args .LayerOptions , & slo )
3215+ options , parentLayer , err := populateLayerOptions (s , rlstore , rlstores , args .ParentLayer , args .LayerOptions )
3216+ if err != nil {
3217+ return nil , err
3218+ }
3219+ layer , _ , err = s .putLayer (rlstore , args .ID , parentLayer , args .Names , args .MountLabel , args .Writeable , options , & slo )
32023220 return layer , err
32033221}
32043222
0 commit comments