@@ -10,6 +10,7 @@ import (
1010 "reflect"
1111
1212 "github.com/Sirupsen/logrus"
13+ "github.com/docker/distribution"
1314 "github.com/docker/docker/image"
1415 "github.com/docker/docker/image/v1"
1516 "github.com/docker/docker/layer"
@@ -63,6 +64,10 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
6364 var parentLinks []parentLink
6465
6566 for _ , m := range manifest {
67+ if m .LayerSources != nil && ! layer .ForeignSourceSupported () {
68+ return fmt .Errorf ("invalid manifest, foreign layers not supported on this operating system" )
69+ }
70+
6671 configPath , err := safePath (tmpDir , m .Config )
6772 if err != nil {
6873 return err
@@ -92,7 +97,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
9297 r .Append (diffID )
9398 newLayer , err := l .ls .Get (r .ChainID ())
9499 if err != nil {
95- newLayer , err = l .loadLayer (layerPath , rootFS , diffID .String (), progressOutput )
100+ newLayer , err = l .loadLayer (layerPath , rootFS , diffID .String (), m . LayerSources [ diffID ], progressOutput )
96101 if err != nil {
97102 return err
98103 }
@@ -151,7 +156,7 @@ func (l *tarexporter) setParentID(id, parentID image.ID) error {
151156 return l .is .SetParent (id , parentID )
152157}
153158
154- func (l * tarexporter ) loadLayer (filename string , rootFS image.RootFS , id string , progressOutput progress.Output ) (layer.Layer , error ) {
159+ func (l * tarexporter ) loadLayer (filename string , rootFS image.RootFS , id string , foreignSrc * distribution. Descriptor , progressOutput progress.Output ) (layer.Layer , error ) {
155160 rawTar , err := os .Open (filename )
156161 if err != nil {
157162 logrus .Debugf ("Error reading embedded tar: %v" , err )
@@ -174,9 +179,9 @@ func (l *tarexporter) loadLayer(filename string, rootFS image.RootFS, id string,
174179
175180 progressReader := progress .NewProgressReader (inflatedLayerData , progressOutput , fileInfo .Size (), stringid .TruncateID (id ), "Loading layer" )
176181
177- return l .ls .Register (progressReader , rootFS .ChainID ())
182+ return l .ls .RegisterForeign (progressReader , rootFS .ChainID (), foreignSrc )
178183 }
179- return l .ls .Register (inflatedLayerData , rootFS .ChainID ())
184+ return l .ls .RegisterForeign (inflatedLayerData , rootFS .ChainID (), foreignSrc )
180185}
181186
182187func (l * tarexporter ) setLoadedTag (ref reference.NamedTagged , imgID image.ID , outStream io.Writer ) error {
@@ -298,7 +303,7 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str
298303 if err != nil {
299304 return err
300305 }
301- newLayer , err := l .loadLayer (layerPath , * rootFS , oldID , progressOutput )
306+ newLayer , err := l .loadLayer (layerPath , * rootFS , oldID , nil , progressOutput )
302307 if err != nil {
303308 return err
304309 }
0 commit comments