2018-02-05 16:05:59 -05:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2015-11-18 17:15:00 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"bytes"
|
2016-04-21 12:08:37 -04:00
|
|
|
"fmt"
|
2015-11-18 17:15:00 -05:00
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-25 19:39:54 -05:00
|
|
|
func (el *emptyLayer) TarStream() (io.ReadCloser, error) {
|
2015-11-18 17:15:00 -05:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
tarWriter := tar.NewWriter(buf)
|
|
|
|
tarWriter.Close()
|
2021-08-24 06:10:50 -04:00
|
|
|
return io.NopCloser(buf), nil
|
2015-11-18 17:15:00 -05:00
|
|
|
}
|
|
|
|
|
2016-11-02 19:13:53 -04:00
|
|
|
func (el *emptyLayer) TarStreamFrom(p ChainID) (io.ReadCloser, error) {
|
|
|
|
if p == "" {
|
|
|
|
return el.TarStream()
|
|
|
|
}
|
2016-04-21 12:08:37 -04:00
|
|
|
return nil, fmt.Errorf("can't get parent tar stream of an empty layer")
|
|
|
|
}
|
|
|
|
|
2015-11-18 17:15:00 -05:00
|
|
|
func (el *emptyLayer) ChainID() ChainID {
|
|
|
|
return ChainID(DigestSHA256EmptyTar)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) DiffID() DiffID {
|
|
|
|
return DigestSHA256EmptyTar
|
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) Parent() Layer {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-21 13:01:34 -05:00
|
|
|
func (el *emptyLayer) Size() int64 {
|
|
|
|
return 0
|
2015-11-18 17:15:00 -05:00
|
|
|
}
|
|
|
|
|
2022-01-21 13:01:34 -05:00
|
|
|
func (el *emptyLayer) DiffSize() int64 {
|
|
|
|
return 0
|
2015-11-18 17:15:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (el *emptyLayer) Metadata() (map[string]string, error) {
|
|
|
|
return make(map[string]string), nil
|
|
|
|
}
|
2017-05-14 14:18:48 -04:00
|
|
|
|
|
|
|
// IsEmpty returns true if the layer is an EmptyLayer
|
|
|
|
func IsEmpty(diffID DiffID) bool {
|
|
|
|
return diffID == DigestSHA256EmptyTar
|
|
|
|
}
|