mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15252 from coolljt0725/14765_enable_golint_3
Enable golint in pkg/archive
This commit is contained in:
commit
8534090476
19 changed files with 84 additions and 41 deletions
|
@ -326,7 +326,7 @@ func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Driver) applyDiff(id string, diff archive.ArchiveReader) error {
|
func (a *Driver) applyDiff(id string, diff archive.Reader) error {
|
||||||
return chrootarchive.UntarUncompressed(diff, path.Join(a.rootPath(), "diff", id), nil)
|
return chrootarchive.UntarUncompressed(diff, path.Join(a.rootPath(), "diff", id), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ func (a *Driver) DiffSize(id, parent string) (size int64, err error) {
|
||||||
// ApplyDiff extracts the changeset from the given diff into the
|
// ApplyDiff extracts the changeset from the given diff into the
|
||||||
// layer with the specified id and parent, returning the size of the
|
// layer with the specified id and parent, returning the size of the
|
||||||
// new layer in bytes.
|
// new layer in bytes.
|
||||||
func (a *Driver) ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error) {
|
func (a *Driver) ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error) {
|
||||||
// AUFS doesn't need the parent id to apply the diff.
|
// AUFS doesn't need the parent id to apply the diff.
|
||||||
if err = a.applyDiff(id, diff); err != nil {
|
if err = a.applyDiff(id, diff); err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -77,8 +77,8 @@ type Driver interface {
|
||||||
// ApplyDiff extracts the changeset from the given diff into the
|
// ApplyDiff extracts the changeset from the given diff into the
|
||||||
// layer with the specified id and parent, returning the size of the
|
// layer with the specified id and parent, returning the size of the
|
||||||
// new layer in bytes.
|
// new layer in bytes.
|
||||||
// The archive.ArchiveReader must be an uncompressed stream.
|
// The archive.Reader must be an uncompressed stream.
|
||||||
ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error)
|
ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error)
|
||||||
// DiffSize calculates the changes between the specified id
|
// DiffSize calculates the changes between the specified id
|
||||||
// and its parent and returns the size in bytes of the changes
|
// and its parent and returns the size in bytes of the changes
|
||||||
// relative to its base filesystem directory.
|
// relative to its base filesystem directory.
|
||||||
|
|
|
@ -11,7 +11,7 @@ type WindowsGraphDriver interface {
|
||||||
LayerIdsToPaths(ids []string) []string
|
LayerIdsToPaths(ids []string) []string
|
||||||
Info() hcsshim.DriverInfo
|
Info() hcsshim.DriverInfo
|
||||||
Export(id string, parentLayerPaths []string) (archive.Archive, error)
|
Export(id string, parentLayerPaths []string) (archive.Archive, error)
|
||||||
Import(id string, layerData archive.ArchiveReader, parentLayerPaths []string) (int64, error)
|
Import(id string, layerData archive.Reader, parentLayerPaths []string) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -25,7 +25,7 @@ type naiveDiffDriver struct {
|
||||||
// it may or may not support on its own:
|
// it may or may not support on its own:
|
||||||
// Diff(id, parent string) (archive.Archive, error)
|
// Diff(id, parent string) (archive.Archive, error)
|
||||||
// Changes(id, parent string) ([]archive.Change, error)
|
// Changes(id, parent string) ([]archive.Change, error)
|
||||||
// ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error)
|
// ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error)
|
||||||
// DiffSize(id, parent string) (size int64, err error)
|
// DiffSize(id, parent string) (size int64, err error)
|
||||||
func NaiveDiffDriver(driver ProtoDriver) Driver {
|
func NaiveDiffDriver(driver ProtoDriver) Driver {
|
||||||
return &naiveDiffDriver{ProtoDriver: driver}
|
return &naiveDiffDriver{ProtoDriver: driver}
|
||||||
|
@ -109,7 +109,7 @@ func (gdw *naiveDiffDriver) Changes(id, parent string) ([]archive.Change, error)
|
||||||
// ApplyDiff extracts the changeset from the given diff into the
|
// ApplyDiff extracts the changeset from the given diff into the
|
||||||
// layer with the specified id and parent, returning the size of the
|
// layer with the specified id and parent, returning the size of the
|
||||||
// new layer in bytes.
|
// new layer in bytes.
|
||||||
func (gdw *naiveDiffDriver) ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error) {
|
func (gdw *naiveDiffDriver) ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error) {
|
||||||
driver := gdw.ProtoDriver
|
driver := gdw.ProtoDriver
|
||||||
|
|
||||||
// Mount the root filesystem so we can apply the diff/layer.
|
// Mount the root filesystem so we can apply the diff/layer.
|
||||||
|
|
|
@ -28,7 +28,7 @@ var (
|
||||||
|
|
||||||
type ApplyDiffProtoDriver interface {
|
type ApplyDiffProtoDriver interface {
|
||||||
graphdriver.ProtoDriver
|
graphdriver.ProtoDriver
|
||||||
ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error)
|
ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type naiveDiffDriverWithApply struct {
|
type naiveDiffDriverWithApply struct {
|
||||||
|
@ -43,7 +43,7 @@ func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver) graphdriver.Driver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.ArchiveReader) (int64, error) {
|
func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.Reader) (int64, error) {
|
||||||
b, err := d.applyDiff.ApplyDiff(id, parent, diff)
|
b, err := d.applyDiff.ApplyDiff(id, parent, diff)
|
||||||
if err == ErrApplyDiffFallback {
|
if err == ErrApplyDiffFallback {
|
||||||
return d.Driver.ApplyDiff(id, parent, diff)
|
return d.Driver.ApplyDiff(id, parent, diff)
|
||||||
|
@ -373,7 +373,7 @@ func (d *Driver) Put(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) ApplyDiff(id string, parent string, diff archive.ArchiveReader) (size int64, err error) {
|
func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
|
|
||||||
if parent == "" {
|
if parent == "" {
|
||||||
|
|
|
@ -171,7 +171,7 @@ func (d *WindowsGraphDriver) Changes(id, parent string) ([]archive.Change, error
|
||||||
// ApplyDiff extracts the changeset from the given diff into the
|
// ApplyDiff extracts the changeset from the given diff into the
|
||||||
// layer with the specified id and parent, returning the size of the
|
// layer with the specified id and parent, returning the size of the
|
||||||
// new layer in bytes.
|
// new layer in bytes.
|
||||||
func (d *WindowsGraphDriver) ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error) {
|
func (d *WindowsGraphDriver) ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error) {
|
||||||
start := time.Now().UTC()
|
start := time.Now().UTC()
|
||||||
logrus.Debugf("WindowsGraphDriver ApplyDiff: Start untar layer")
|
logrus.Debugf("WindowsGraphDriver ApplyDiff: Start untar layer")
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ func (d *WindowsGraphDriver) Export(id string, parentLayerPaths []string) (arch
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *WindowsGraphDriver) Import(id string, layerData archive.ArchiveReader, parentLayerPaths []string) (size int64, err error) {
|
func (d *WindowsGraphDriver) Import(id string, layerData archive.Reader, parentLayerPaths []string) (size int64, err error) {
|
||||||
layerFs, err := d.Get(id, "")
|
layerFs, err := d.Get(id, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -198,7 +198,7 @@ func (graph *Graph) Get(name string) (*image.Image, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new image and registers it in the graph.
|
// Create creates a new image and registers it in the graph.
|
||||||
func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
|
func (graph *Graph) Create(layerData archive.Reader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
|
||||||
img := &image.Image{
|
img := &image.Image{
|
||||||
ID: stringid.GenerateRandomID(),
|
ID: stringid.GenerateRandomID(),
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
|
@ -223,7 +223,7 @@ func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, contain
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register imports a pre-existing image into the graph.
|
// Register imports a pre-existing image into the graph.
|
||||||
func (graph *Graph) Register(img *image.Image, layerData archive.ArchiveReader) (err error) {
|
func (graph *Graph) Register(img *image.Image, layerData archive.Reader) (err error) {
|
||||||
|
|
||||||
if err := image.ValidateID(img.ID); err != nil {
|
if err := image.ValidateID(img.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -535,7 +535,7 @@ func jsonPath(root string) string {
|
||||||
return filepath.Join(root, jsonFileName)
|
return filepath.Join(root, jsonFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) disassembleAndApplyTarLayer(img *image.Image, layerData archive.ArchiveReader, root string) error {
|
func (graph *Graph) disassembleAndApplyTarLayer(img *image.Image, layerData archive.Reader, root string) error {
|
||||||
// this is saving the tar-split metadata
|
// this is saving the tar-split metadata
|
||||||
mf, err := os.OpenFile(filepath.Join(root, tarDataFileName), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
|
mf, err := os.OpenFile(filepath.Join(root, tarDataFileName), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -558,7 +558,7 @@ func (graph *Graph) disassembleAndApplyTarLayer(img *image.Image, layerData arch
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if img.Size, err = graph.driver.ApplyDiff(img.ID, img.Parent, archive.ArchiveReader(rdr)); err != nil {
|
if img.Size, err = graph.driver.ApplyDiff(img.ID, img.Parent, archive.Reader(rdr)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ func SetupInitLayer(initLayer string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRootFilesystemInDriver(graph *Graph, img *image.Image, layerData archive.ArchiveReader) error {
|
func createRootFilesystemInDriver(graph *Graph, img *image.Image, layerData archive.Reader) error {
|
||||||
if err := graph.driver.Create(img.ID, img.Parent); err != nil {
|
if err := graph.driver.Create(img.ID, img.Parent); err != nil {
|
||||||
return fmt.Errorf("Driver %s failed to create image rootfs %s: %s", graph.driver, img.ID, err)
|
return fmt.Errorf("Driver %s failed to create image rootfs %s: %s", graph.driver, img.ID, err)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ func (graph *Graph) restoreBaseImages() ([]string, error) {
|
||||||
// storeImage stores file system layer data for the given image to the
|
// storeImage stores file system layer data for the given image to the
|
||||||
// graph's storage driver. Image metadata is stored in a file
|
// graph's storage driver. Image metadata is stored in a file
|
||||||
// at the specified root directory.
|
// at the specified root directory.
|
||||||
func (graph *Graph) storeImage(img *image.Image, layerData archive.ArchiveReader, root string) (err error) {
|
func (graph *Graph) storeImage(img *image.Image, layerData archive.Reader, root string) (err error) {
|
||||||
// Store the layer. If layerData is not nil, unpack it into the new layer
|
// Store the layer. If layerData is not nil, unpack it into the new layer
|
||||||
if layerData != nil {
|
if layerData != nil {
|
||||||
if err := graph.disassembleAndApplyTarLayer(img, layerData, root); err != nil {
|
if err := graph.disassembleAndApplyTarLayer(img, layerData, root); err != nil {
|
||||||
|
|
|
@ -19,7 +19,7 @@ func SetupInitLayer(initLayer string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRootFilesystemInDriver(graph *Graph, img *image.Image, layerData archive.ArchiveReader) error {
|
func createRootFilesystemInDriver(graph *Graph, img *image.Image, layerData archive.Reader) error {
|
||||||
if wd, ok := graph.driver.(*windows.WindowsGraphDriver); ok {
|
if wd, ok := graph.driver.(*windows.WindowsGraphDriver); ok {
|
||||||
if img.Container != "" && layerData == nil {
|
if img.Container != "" && layerData == nil {
|
||||||
logrus.Debugf("Copying from container %s.", img.Container)
|
logrus.Debugf("Copying from container %s.", img.Container)
|
||||||
|
@ -71,7 +71,7 @@ func (graph *Graph) ParentLayerIds(img *image.Image) (ids []string, err error) {
|
||||||
// storeImage stores file system layer data for the given image to the
|
// storeImage stores file system layer data for the given image to the
|
||||||
// graph's storage driver. Image metadata is stored in a file
|
// graph's storage driver. Image metadata is stored in a file
|
||||||
// at the specified root directory.
|
// at the specified root directory.
|
||||||
func (graph *Graph) storeImage(img *image.Image, layerData archive.ArchiveReader, root string) (err error) {
|
func (graph *Graph) storeImage(img *image.Image, layerData archive.Reader, root string) (err error) {
|
||||||
|
|
||||||
if wd, ok := graph.driver.(*windows.WindowsGraphDriver); ok {
|
if wd, ok := graph.driver.(*windows.WindowsGraphDriver); ok {
|
||||||
// Store the layer. If layerData is not nil and this isn't a base image,
|
// Store the layer. If layerData is not nil and this isn't a base image,
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
func (s *TagStore) Import(src string, repo string, tag string, inConfig io.ReadCloser, outStream io.Writer, containerConfig *runconfig.Config) error {
|
func (s *TagStore) Import(src string, repo string, tag string, inConfig io.ReadCloser, outStream io.Writer, containerConfig *runconfig.Config) error {
|
||||||
var (
|
var (
|
||||||
sf = streamformatter.NewJSONStreamFormatter()
|
sf = streamformatter.NewJSONStreamFormatter()
|
||||||
archive archive.ArchiveReader
|
archive archive.Reader
|
||||||
resp *http.Response
|
resp *http.Response
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ packages=(
|
||||||
daemon/graphdriver/vfs
|
daemon/graphdriver/vfs
|
||||||
image
|
image
|
||||||
integration-cli
|
integration-cli
|
||||||
|
pkg/archive
|
||||||
pkg/broadcastwriter
|
pkg/broadcastwriter
|
||||||
pkg/chrootarchive
|
pkg/chrootarchive
|
||||||
pkg/directory
|
pkg/directory
|
||||||
|
|
|
@ -25,12 +25,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Archive io.ReadCloser
|
// Archive is a type of io.ReadCloser which has two interfaces Read and Closer.
|
||||||
ArchiveReader io.Reader
|
Archive io.ReadCloser
|
||||||
Compression int
|
// Reader is a type of io.Reader.
|
||||||
|
Reader io.Reader
|
||||||
|
// Compression is the state represtents if compressed or not.
|
||||||
|
Compression int
|
||||||
|
// TarChownOptions wraps the chown options UID and GID.
|
||||||
TarChownOptions struct {
|
TarChownOptions struct {
|
||||||
UID, GID int
|
UID, GID int
|
||||||
}
|
}
|
||||||
|
// TarOptions wraps the tar options.
|
||||||
TarOptions struct {
|
TarOptions struct {
|
||||||
IncludeFiles []string
|
IncludeFiles []string
|
||||||
ExcludePatterns []string
|
ExcludePatterns []string
|
||||||
|
@ -59,17 +64,23 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// ErrNotImplemented is the error message of function not implemented.
|
||||||
ErrNotImplemented = errors.New("Function not implemented")
|
ErrNotImplemented = errors.New("Function not implemented")
|
||||||
defaultArchiver = &Archiver{Untar}
|
defaultArchiver = &Archiver{Untar}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Uncompressed represents the uncompressed.
|
||||||
Uncompressed Compression = iota
|
Uncompressed Compression = iota
|
||||||
|
// Bzip2 is bzip2 compression algorithm.
|
||||||
Bzip2
|
Bzip2
|
||||||
|
// Gzip is gzip compression algorithm.
|
||||||
Gzip
|
Gzip
|
||||||
|
// Xz is xz compression algorithm.
|
||||||
Xz
|
Xz
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsArchive checks if it is a archive by the header.
|
||||||
func IsArchive(header []byte) bool {
|
func IsArchive(header []byte) bool {
|
||||||
compression := DetectCompression(header)
|
compression := DetectCompression(header)
|
||||||
if compression != Uncompressed {
|
if compression != Uncompressed {
|
||||||
|
@ -80,6 +91,7 @@ func IsArchive(header []byte) bool {
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DetectCompression detects the compression algorithm of the source.
|
||||||
func DetectCompression(source []byte) Compression {
|
func DetectCompression(source []byte) Compression {
|
||||||
for compression, m := range map[Compression][]byte{
|
for compression, m := range map[Compression][]byte{
|
||||||
Bzip2: {0x42, 0x5A, 0x68},
|
Bzip2: {0x42, 0x5A, 0x68},
|
||||||
|
@ -103,6 +115,7 @@ func xzDecompress(archive io.Reader) (io.ReadCloser, error) {
|
||||||
return CmdStream(exec.Command(args[0], args[1:]...), archive)
|
return CmdStream(exec.Command(args[0], args[1:]...), archive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecompressStream decompress the archive and returns a ReaderCloser with the decompressed archive.
|
||||||
func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
|
func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
|
||||||
p := pools.BufioReader32KPool
|
p := pools.BufioReader32KPool
|
||||||
buf := p.Get(archive)
|
buf := p.Get(archive)
|
||||||
|
@ -139,6 +152,7 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CompressStream compresses the dest with specified compression algorithm.
|
||||||
func CompressStream(dest io.WriteCloser, compression Compression) (io.WriteCloser, error) {
|
func CompressStream(dest io.WriteCloser, compression Compression) (io.WriteCloser, error) {
|
||||||
p := pools.BufioWriter32KPool
|
p := pools.BufioWriter32KPool
|
||||||
buf := p.Get(dest)
|
buf := p.Get(dest)
|
||||||
|
@ -159,6 +173,7 @@ func CompressStream(dest io.WriteCloser, compression Compression) (io.WriteClose
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extension returns the extension of a file that uses the specified compression algorithm.
|
||||||
func (compression *Compression) Extension() string {
|
func (compression *Compression) Extension() string {
|
||||||
switch *compression {
|
switch *compression {
|
||||||
case Uncompressed:
|
case Uncompressed:
|
||||||
|
@ -530,6 +545,7 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
|
||||||
return pipeReader, nil
|
return pipeReader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unpack unpacks the decompressedArchive to dest with options.
|
||||||
func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error {
|
func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error {
|
||||||
tr := tar.NewReader(decompressedArchive)
|
tr := tar.NewReader(decompressedArchive)
|
||||||
trBuf := pools.BufioReader32KPool.Get(nil)
|
trBuf := pools.BufioReader32KPool.Get(nil)
|
||||||
|
@ -643,7 +659,7 @@ func Untar(tarArchive io.Reader, dest string, options *TarOptions) error {
|
||||||
return untarHandler(tarArchive, dest, options, true)
|
return untarHandler(tarArchive, dest, options, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Untar reads a stream of bytes from `archive`, parses it as a tar archive,
|
// UntarUncompressed reads a stream of bytes from `archive`, parses it as a tar archive,
|
||||||
// and unpacks it into the directory at `dest`.
|
// and unpacks it into the directory at `dest`.
|
||||||
// The archive must be an uncompressed stream.
|
// The archive must be an uncompressed stream.
|
||||||
func UntarUncompressed(tarArchive io.Reader, dest string, options *TarOptions) error {
|
func UntarUncompressed(tarArchive io.Reader, dest string, options *TarOptions) error {
|
||||||
|
@ -663,7 +679,7 @@ func untarHandler(tarArchive io.Reader, dest string, options *TarOptions, decomp
|
||||||
options.ExcludePatterns = []string{}
|
options.ExcludePatterns = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var r io.Reader = tarArchive
|
r := tarArchive
|
||||||
if decompress {
|
if decompress {
|
||||||
decompressedArchive, err := DecompressStream(tarArchive)
|
decompressedArchive, err := DecompressStream(tarArchive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -676,6 +692,8 @@ func untarHandler(tarArchive io.Reader, dest string, options *TarOptions, decomp
|
||||||
return Unpack(r, dest, options)
|
return Unpack(r, dest, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other.
|
||||||
|
// If either Tar or Untar fails, TarUntar aborts and returns the error.
|
||||||
func (archiver *Archiver) TarUntar(src, dst string) error {
|
func (archiver *Archiver) TarUntar(src, dst string) error {
|
||||||
logrus.Debugf("TarUntar(%s %s)", src, dst)
|
logrus.Debugf("TarUntar(%s %s)", src, dst)
|
||||||
archive, err := TarWithOptions(src, &TarOptions{Compression: Uncompressed})
|
archive, err := TarWithOptions(src, &TarOptions{Compression: Uncompressed})
|
||||||
|
@ -692,6 +710,7 @@ func TarUntar(src, dst string) error {
|
||||||
return defaultArchiver.TarUntar(src, dst)
|
return defaultArchiver.TarUntar(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UntarPath untar a file from path to a destination, src is the source tar file path.
|
||||||
func (archiver *Archiver) UntarPath(src, dst string) error {
|
func (archiver *Archiver) UntarPath(src, dst string) error {
|
||||||
archive, err := os.Open(src)
|
archive, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -710,6 +729,10 @@ func UntarPath(src, dst string) error {
|
||||||
return defaultArchiver.UntarPath(src, dst)
|
return defaultArchiver.UntarPath(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyWithTar creates a tar archive of filesystem path `src`, and
|
||||||
|
// unpacks it at filesystem path `dst`.
|
||||||
|
// The archive is streamed directly with fixed buffering and no
|
||||||
|
// intermediary disk IO.
|
||||||
func (archiver *Archiver) CopyWithTar(src, dst string) error {
|
func (archiver *Archiver) CopyWithTar(src, dst string) error {
|
||||||
srcSt, err := os.Stat(src)
|
srcSt, err := os.Stat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -735,6 +758,9 @@ func CopyWithTar(src, dst string) error {
|
||||||
return defaultArchiver.CopyWithTar(src, dst)
|
return defaultArchiver.CopyWithTar(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyFileWithTar emulates the behavior of the 'cp' command-line
|
||||||
|
// for a single file. It copies a regular file from path `src` to
|
||||||
|
// path `dst`, and preserves all its metadata.
|
||||||
func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
|
func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
|
||||||
logrus.Debugf("CopyFileWithTar(%s, %s)", src, dst)
|
logrus.Debugf("CopyFileWithTar(%s, %s)", src, dst)
|
||||||
srcSt, err := os.Stat(src)
|
srcSt, err := os.Stat(src)
|
||||||
|
@ -878,6 +904,8 @@ func NewTempArchive(src Archive, dir string) (*TempArchive, error) {
|
||||||
return &TempArchive{File: f, Size: size}, nil
|
return &TempArchive{File: f, Size: size}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TempArchive is a temporary archive. The archive can only be read once - as soon as reading completes,
|
||||||
|
// the file will be deleted.
|
||||||
type TempArchive struct {
|
type TempArchive struct {
|
||||||
*os.File
|
*os.File
|
||||||
Size int64 // Pre-computed from Stat().Size() as a convenience
|
Size int64 // Pre-computed from Stat().Size() as a convenience
|
||||||
|
|
|
@ -18,14 +18,22 @@ import (
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ChangeType represents the change type.
|
||||||
type ChangeType int
|
type ChangeType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// ChangeModify represents the modify operation.
|
||||||
ChangeModify = iota
|
ChangeModify = iota
|
||||||
|
// ChangeAdd represents the add operation.
|
||||||
ChangeAdd
|
ChangeAdd
|
||||||
|
// ChangeDelete represents the delete operation.
|
||||||
ChangeDelete
|
ChangeDelete
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Change represents a change, it wraps the change type and path.
|
||||||
|
// It describes changes of the files in the path respect to the
|
||||||
|
// parent layers. The change could be modify, add, delete.
|
||||||
|
// This is used for layer diff.
|
||||||
type Change struct {
|
type Change struct {
|
||||||
Path string
|
Path string
|
||||||
Kind ChangeType
|
Kind ChangeType
|
||||||
|
@ -161,6 +169,7 @@ func Changes(layers []string, rw string) ([]Change, error) {
|
||||||
return changes, nil
|
return changes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FileInfo describes the information of a file.
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
parent *FileInfo
|
parent *FileInfo
|
||||||
name string
|
name string
|
||||||
|
@ -170,11 +179,12 @@ type FileInfo struct {
|
||||||
added bool
|
added bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (root *FileInfo) LookUp(path string) *FileInfo {
|
// LookUp looks up the file information of a file.
|
||||||
|
func (info *FileInfo) LookUp(path string) *FileInfo {
|
||||||
// As this runs on the daemon side, file paths are OS specific.
|
// As this runs on the daemon side, file paths are OS specific.
|
||||||
parent := root
|
parent := info
|
||||||
if path == string(os.PathSeparator) {
|
if path == string(os.PathSeparator) {
|
||||||
return root
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
pathElements := strings.Split(path, string(os.PathSeparator))
|
pathElements := strings.Split(path, string(os.PathSeparator))
|
||||||
|
@ -275,6 +285,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Changes add changes to file information.
|
||||||
func (info *FileInfo) Changes(oldInfo *FileInfo) []Change {
|
func (info *FileInfo) Changes(oldInfo *FileInfo) []Change {
|
||||||
var changes []Change
|
var changes []Change
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ func CopyInfoDestinationPath(path string) (info CopyInfo, err error) {
|
||||||
// contain the archived resource described by srcInfo, to the destination
|
// contain the archived resource described by srcInfo, to the destination
|
||||||
// described by dstInfo. Returns the possibly modified content archive along
|
// described by dstInfo. Returns the possibly modified content archive along
|
||||||
// with the path to the destination directory which it should be extracted to.
|
// with the path to the destination directory which it should be extracted to.
|
||||||
func PrepareArchiveCopy(srcContent ArchiveReader, srcInfo, dstInfo CopyInfo) (dstDir string, content Archive, err error) {
|
func PrepareArchiveCopy(srcContent Reader, srcInfo, dstInfo CopyInfo) (dstDir string, content Archive, err error) {
|
||||||
// Separate the destination path between its directory and base
|
// Separate the destination path between its directory and base
|
||||||
// components in case the source archive contents need to be rebased.
|
// components in case the source archive contents need to be rebased.
|
||||||
dstDir, dstBase := SplitPathDirEntry(dstInfo.Path)
|
dstDir, dstBase := SplitPathDirEntry(dstInfo.Path)
|
||||||
|
@ -296,7 +296,7 @@ func PrepareArchiveCopy(srcContent ArchiveReader, srcInfo, dstInfo CopyInfo) (ds
|
||||||
|
|
||||||
// rebaseArchiveEntries rewrites the given srcContent archive replacing
|
// rebaseArchiveEntries rewrites the given srcContent archive replacing
|
||||||
// an occurance of oldBase with newBase at the beginning of entry names.
|
// an occurance of oldBase with newBase at the beginning of entry names.
|
||||||
func rebaseArchiveEntries(srcContent ArchiveReader, oldBase, newBase string) Archive {
|
func rebaseArchiveEntries(srcContent Reader, oldBase, newBase string) Archive {
|
||||||
if oldBase == "/" {
|
if oldBase == "/" {
|
||||||
// If oldBase specifies the root directory, use an empty string as
|
// If oldBase specifies the root directory, use an empty string as
|
||||||
// oldBase instead so that newBase doesn't replace the path separator
|
// oldBase instead so that newBase doesn't replace the path separator
|
||||||
|
@ -368,7 +368,7 @@ func CopyResource(srcPath, dstPath string) error {
|
||||||
|
|
||||||
// CopyTo handles extracting the given content whose
|
// CopyTo handles extracting the given content whose
|
||||||
// entries should be sourced from srcInfo to dstPath.
|
// entries should be sourced from srcInfo to dstPath.
|
||||||
func CopyTo(content ArchiveReader, srcInfo CopyInfo, dstPath string) error {
|
func CopyTo(content Reader, srcInfo CopyInfo, dstPath string) error {
|
||||||
// The destination path need not exist, but CopyInfoDestinationPath will
|
// The destination path need not exist, but CopyInfoDestinationPath will
|
||||||
// ensure that at least the parent directory exists.
|
// ensure that at least the parent directory exists.
|
||||||
dstInfo, err := CopyInfoDestinationPath(dstPath)
|
dstInfo, err := CopyInfoDestinationPath(dstPath)
|
||||||
|
|
|
@ -16,7 +16,10 @@ import (
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UnpackLayer(dest string, layer ArchiveReader) (size int64, err error) {
|
// UnpackLayer unpack `layer` to a `dest`. The stream `layer` can be
|
||||||
|
// compressed or uncompressed.
|
||||||
|
// Returns the size in bytes of the contents of the layer.
|
||||||
|
func UnpackLayer(dest string, layer Reader) (size int64, err error) {
|
||||||
tr := tar.NewReader(layer)
|
tr := tar.NewReader(layer)
|
||||||
trBuf := pools.BufioReader32KPool.Get(tr)
|
trBuf := pools.BufioReader32KPool.Get(tr)
|
||||||
defer pools.BufioReader32KPool.Put(trBuf)
|
defer pools.BufioReader32KPool.Put(trBuf)
|
||||||
|
@ -177,7 +180,7 @@ func UnpackLayer(dest string, layer ArchiveReader) (size int64, err error) {
|
||||||
// and applies it to the directory `dest`. The stream `layer` can be
|
// and applies it to the directory `dest`. The stream `layer` can be
|
||||||
// compressed or uncompressed.
|
// compressed or uncompressed.
|
||||||
// Returns the size in bytes of the contents of the layer.
|
// Returns the size in bytes of the contents of the layer.
|
||||||
func ApplyLayer(dest string, layer ArchiveReader) (int64, error) {
|
func ApplyLayer(dest string, layer Reader) (int64, error) {
|
||||||
return applyLayerHandler(dest, layer, true)
|
return applyLayerHandler(dest, layer, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,12 +188,12 @@ func ApplyLayer(dest string, layer ArchiveReader) (int64, error) {
|
||||||
// `layer`, and applies it to the directory `dest`. The stream `layer`
|
// `layer`, and applies it to the directory `dest`. The stream `layer`
|
||||||
// can only be uncompressed.
|
// can only be uncompressed.
|
||||||
// Returns the size in bytes of the contents of the layer.
|
// Returns the size in bytes of the contents of the layer.
|
||||||
func ApplyUncompressedLayer(dest string, layer ArchiveReader) (int64, error) {
|
func ApplyUncompressedLayer(dest string, layer Reader) (int64, error) {
|
||||||
return applyLayerHandler(dest, layer, false)
|
return applyLayerHandler(dest, layer, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the bulk load of ApplyLayer, but allow for not calling DecompressStream
|
// do the bulk load of ApplyLayer, but allow for not calling DecompressStream
|
||||||
func applyLayerHandler(dest string, layer ArchiveReader, decompress bool) (int64, error) {
|
func applyLayerHandler(dest string, layer Reader, decompress bool) (int64, error) {
|
||||||
dest = filepath.Clean(dest)
|
dest = filepath.Clean(dest)
|
||||||
|
|
||||||
// We need to be able to set any perms
|
// We need to be able to set any perms
|
||||||
|
|
|
@ -16,7 +16,7 @@ var testUntarFns = map[string]func(string, io.Reader) error{
|
||||||
return Untar(r, dest, nil)
|
return Untar(r, dest, nil)
|
||||||
},
|
},
|
||||||
"applylayer": func(dest string, r io.Reader) error {
|
"applylayer": func(dest string, r io.Reader) error {
|
||||||
_, err := ApplyLayer(dest, ArchiveReader(r))
|
_, err := ApplyLayer(dest, Reader(r))
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/docker/docker/pkg/archive"
|
||||||
// and applies it to the directory `dest`. The stream `layer` can only be
|
// and applies it to the directory `dest`. The stream `layer` can only be
|
||||||
// uncompressed.
|
// uncompressed.
|
||||||
// Returns the size in bytes of the contents of the layer.
|
// Returns the size in bytes of the contents of the layer.
|
||||||
func ApplyLayer(dest string, layer archive.ArchiveReader) (size int64, err error) {
|
func ApplyLayer(dest string, layer archive.Reader) (size int64, err error) {
|
||||||
return applyLayerHandler(dest, layer, true)
|
return applyLayerHandler(dest, layer, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,6 @@ func ApplyLayer(dest string, layer archive.ArchiveReader) (size int64, err error
|
||||||
// `layer`, and applies it to the directory `dest`. The stream `layer`
|
// `layer`, and applies it to the directory `dest`. The stream `layer`
|
||||||
// can only be uncompressed.
|
// can only be uncompressed.
|
||||||
// Returns the size in bytes of the contents of the layer.
|
// Returns the size in bytes of the contents of the layer.
|
||||||
func ApplyUncompressedLayer(dest string, layer archive.ArchiveReader) (int64, error) {
|
func ApplyUncompressedLayer(dest string, layer archive.Reader) (int64, error) {
|
||||||
return applyLayerHandler(dest, layer, false)
|
return applyLayerHandler(dest, layer, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ func applyLayer() {
|
||||||
// applyLayerHandler parses a diff in the standard layer format from `layer`, and
|
// applyLayerHandler parses a diff in the standard layer format from `layer`, and
|
||||||
// applies it to the directory `dest`. Returns the size in bytes of the
|
// applies it to the directory `dest`. Returns the size in bytes of the
|
||||||
// contents of the layer.
|
// contents of the layer.
|
||||||
func applyLayerHandler(dest string, layer archive.ArchiveReader, decompress bool) (size int64, err error) {
|
func applyLayerHandler(dest string, layer archive.Reader, decompress bool) (size int64, err error) {
|
||||||
dest = filepath.Clean(dest)
|
dest = filepath.Clean(dest)
|
||||||
if decompress {
|
if decompress {
|
||||||
decompressed, err := archive.DecompressStream(layer)
|
decompressed, err := archive.DecompressStream(layer)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// applyLayerHandler parses a diff in the standard layer format from `layer`, and
|
// applyLayerHandler parses a diff in the standard layer format from `layer`, and
|
||||||
// applies it to the directory `dest`. Returns the size in bytes of the
|
// applies it to the directory `dest`. Returns the size in bytes of the
|
||||||
// contents of the layer.
|
// contents of the layer.
|
||||||
func applyLayerHandler(dest string, layer archive.ArchiveReader, decompress bool) (size int64, err error) {
|
func applyLayerHandler(dest string, layer archive.Reader, decompress bool) (size int64, err error) {
|
||||||
dest = filepath.Clean(dest)
|
dest = filepath.Clean(dest)
|
||||||
if decompress {
|
if decompress {
|
||||||
decompressed, err := archive.DecompressStream(layer)
|
decompressed, err := archive.DecompressStream(layer)
|
||||||
|
|
Loading…
Add table
Reference in a new issue