From 6622cc970e27a7bf2798d751ed276265a3a2d404 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 2 Nov 2016 16:13:53 -0700 Subject: [PATCH] Cleanup invalid code in overlay2 and layer store The overlay2 change ensures that the correct path is used to resolve the symlink. The current code will not fail since the symlinks are always given a value of "../id/diff" which ends up ignoring the incorrect "link" value. Fix this code so it doesn't cause unexpected errors in the future if the symlink changes. The layerstore cleanup ensures that the empty layer returns a tar stream if the provided parent is empty. Any value other than empty still returns an error since the empty layer has no parent. Currently empty layer is not used anywhere that TarStreamFrom is used but could break in the future if this function is called. Signed-off-by: Derek McGowan (github: dmcgowan) --- daemon/graphdriver/overlay2/overlay.go | 2 +- layer/empty.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index 7ba1251f24..fb590b6463 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -412,7 +412,7 @@ func (d *Driver) getLowerDirs(id string) ([]string, error) { if err != nil { return nil, err } - lowersArray = append(lowersArray, path.Clean(path.Join(d.home, "link", lp))) + lowersArray = append(lowersArray, path.Clean(path.Join(d.home, linkDir, lp))) } } else if !os.IsNotExist(err) { return nil, err diff --git a/layer/empty.go b/layer/empty.go index b68fed9a47..3b6ffc82f7 100644 --- a/layer/empty.go +++ b/layer/empty.go @@ -24,7 +24,10 @@ func (el *emptyLayer) TarStream() (io.ReadCloser, error) { return ioutil.NopCloser(buf), nil } -func (el *emptyLayer) TarStreamFrom(ChainID) (io.ReadCloser, error) { +func (el *emptyLayer) TarStreamFrom(p ChainID) (io.ReadCloser, error) { + if p == "" { + return el.TarStream() + } return nil, fmt.Errorf("can't get parent tar stream of an empty layer") }