2018-02-05 21:05:59 +00:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2015-11-18 22:15:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"bytes"
|
2016-04-21 16:08:37 +00:00
|
|
|
"fmt"
|
2015-11-18 22:15:00 +00:00
|
|
|
"io"
|
2015-11-26 00:39:54 +00:00
|
|
|
"io/ioutil"
|
2015-11-18 22:15:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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{}
|
|
|
|
|
2015-11-26 00:39:54 +00:00
|
|
|
func (el *emptyLayer) TarStream() (io.ReadCloser, error) {
|
2015-11-18 22:15:00 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
tarWriter := tar.NewWriter(buf)
|
|
|
|
tarWriter.Close()
|
2015-11-26 00:39:54 +00:00
|
|
|
return ioutil.NopCloser(buf), nil
|
2015-11-18 22:15:00 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 23:13:53 +00:00
|
|
|
func (el *emptyLayer) TarStreamFrom(p ChainID) (io.ReadCloser, error) {
|
|
|
|
if p == "" {
|
|
|
|
return el.TarStream()
|
|
|
|
}
|
2016-04-21 16:08:37 +00:00
|
|
|
return nil, fmt.Errorf("can't get parent tar stream of an empty layer")
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:15:00 +00:00
|
|
|
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
|
|
|
|
}
|
2017-05-14 18:18:48 +00:00
|
|
|
|
|
|
|
// IsEmpty returns true if the layer is an EmptyLayer
|
|
|
|
func IsEmpty(diffID DiffID) bool {
|
|
|
|
return diffID == DigestSHA256EmptyTar
|
|
|
|
}
|