mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6622cc970e
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 <derek@mcgstyle.net> (github: dmcgowan)
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package layer
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
)
|
|
|
|
// DigestSHA256EmptyTar is the canonical sha256 digest of empty tar file -
|
|
// (1024 NULL bytes)
|
|
const DigestSHA256EmptyTar = DiffID("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef")
|
|
|
|
type emptyLayer struct{}
|
|
|
|
// EmptyLayer is a layer that corresponds to empty tar.
|
|
var EmptyLayer = &emptyLayer{}
|
|
|
|
func (el *emptyLayer) TarStream() (io.ReadCloser, error) {
|
|
buf := new(bytes.Buffer)
|
|
tarWriter := tar.NewWriter(buf)
|
|
tarWriter.Close()
|
|
return ioutil.NopCloser(buf), nil
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
func (el *emptyLayer) ChainID() ChainID {
|
|
return ChainID(DigestSHA256EmptyTar)
|
|
}
|
|
|
|
func (el *emptyLayer) DiffID() DiffID {
|
|
return DigestSHA256EmptyTar
|
|
}
|
|
|
|
func (el *emptyLayer) Parent() Layer {
|
|
return nil
|
|
}
|
|
|
|
func (el *emptyLayer) Size() (size int64, err error) {
|
|
return 0, nil
|
|
}
|
|
|
|
func (el *emptyLayer) DiffSize() (size int64, err error) {
|
|
return 0, nil
|
|
}
|
|
|
|
func (el *emptyLayer) Metadata() (map[string]string, error) {
|
|
return make(map[string]string), nil
|
|
}
|