mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Remove unused functions from archive.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
		
							parent
							
								
									09cd96c5ad
								
							
						
					
					
						commit
						967ef7e6d2
					
				
					 12 changed files with 104 additions and 185 deletions
				
			
		| 
						 | 
					@ -425,7 +425,7 @@ func copyExistingContents(source, destination string) error {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if len(srcList) == 0 {
 | 
							if len(srcList) == 0 {
 | 
				
			||||||
			// If the source volume is empty, copies files from the root into the volume
 | 
								// If the source volume is empty, copies files from the root into the volume
 | 
				
			||||||
			if err := chrootarchive.CopyWithTar(source, destination); err != nil {
 | 
								if err := chrootarchive.NewArchiver(nil).CopyWithTar(source, destination); err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -413,12 +413,7 @@ func (daemon *Daemon) CopyOnBuild(cID, destPath, srcRoot, srcPath string, decomp
 | 
				
			||||||
		destExists = false
 | 
							destExists = false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	archiver := &archive.Archiver{
 | 
						archiver := chrootarchive.NewArchiver(daemon.idMappings)
 | 
				
			||||||
		Untar:   chrootarchive.Untar,
 | 
					 | 
				
			||||||
		UIDMaps: daemon.idMappings.UIDs(),
 | 
					 | 
				
			||||||
		GIDMaps: daemon.idMappings.GIDs(),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	src, err := os.Stat(fullSrcPath)
 | 
						src, err := os.Stat(fullSrcPath)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,9 +20,6 @@ func (daemon *Daemon) tarCopyOptions(container *container.Container, noOverwrite
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &archive.TarOptions{
 | 
						return &archive.TarOptions{
 | 
				
			||||||
		NoOverwriteDirNonDir: noOverwriteDirNonDir,
 | 
							NoOverwriteDirNonDir: noOverwriteDirNonDir,
 | 
				
			||||||
		ChownOpts: &archive.TarChownOptions{
 | 
							ChownOpts:            idtools.IDPair{UID: user.Uid, GID: user.Gid},
 | 
				
			||||||
			UID: user.Uid,
 | 
					 | 
				
			||||||
			GID: user.Gid,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}, nil
 | 
						}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	// CopyWithTar defines the copy method to use.
 | 
						// CopyWithTar defines the copy method to use.
 | 
				
			||||||
	CopyWithTar = chrootarchive.CopyWithTar
 | 
						CopyWithTar = chrootarchive.NewArchiver(nil).CopyWithTar
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -152,7 +152,7 @@ func testDirectory(templateDir string) (dir string, err error) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if templateDir != "" {
 | 
						if templateDir != "" {
 | 
				
			||||||
		if err = archive.CopyWithTar(templateDir, dir); err != nil {
 | 
							if err = archive.NewDefaultArchiver().CopyWithTar(templateDir, dir); err != nil {
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,8 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	graphdriver.ApplyUncompressedLayer = archive.UnpackLayer
 | 
						graphdriver.ApplyUncompressedLayer = archive.UnpackLayer
 | 
				
			||||||
	vfs.CopyWithTar = archive.CopyWithTar
 | 
						defaultArchiver := archive.NewDefaultArchiver()
 | 
				
			||||||
 | 
						vfs.CopyWithTar = defaultArchiver.CopyWithTar
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newVFSGraphDriver(td string) (graphdriver.Driver, error) {
 | 
					func newVFSGraphDriver(td string) (graphdriver.Driver, error) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,6 @@ import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"compress/bzip2"
 | 
						"compress/bzip2"
 | 
				
			||||||
	"compress/gzip"
 | 
						"compress/gzip"
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
| 
						 | 
					@ -31,10 +30,6 @@ type (
 | 
				
			||||||
	Compression int
 | 
						Compression int
 | 
				
			||||||
	// WhiteoutFormat is the format of whiteouts unpacked
 | 
						// WhiteoutFormat is the format of whiteouts unpacked
 | 
				
			||||||
	WhiteoutFormat int
 | 
						WhiteoutFormat int
 | 
				
			||||||
	// TarChownOptions wraps the chown options UID and GID.
 | 
					 | 
				
			||||||
	TarChownOptions struct {
 | 
					 | 
				
			||||||
		UID, GID int
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TarOptions wraps the tar options.
 | 
						// TarOptions wraps the tar options.
 | 
				
			||||||
	TarOptions struct {
 | 
						TarOptions struct {
 | 
				
			||||||
| 
						 | 
					@ -44,7 +39,7 @@ type (
 | 
				
			||||||
		NoLchown         bool
 | 
							NoLchown         bool
 | 
				
			||||||
		UIDMaps          []idtools.IDMap
 | 
							UIDMaps          []idtools.IDMap
 | 
				
			||||||
		GIDMaps          []idtools.IDMap
 | 
							GIDMaps          []idtools.IDMap
 | 
				
			||||||
		ChownOpts        *TarChownOptions
 | 
							ChownOpts        idtools.IDPair
 | 
				
			||||||
		IncludeSourceDir bool
 | 
							IncludeSourceDir bool
 | 
				
			||||||
		// WhiteoutFormat is the expected on disk format for whiteout files.
 | 
							// WhiteoutFormat is the expected on disk format for whiteout files.
 | 
				
			||||||
		// This format will be converted to the standard format on pack
 | 
							// This format will be converted to the standard format on pack
 | 
				
			||||||
| 
						 | 
					@ -58,33 +53,26 @@ type (
 | 
				
			||||||
		RebaseNames map[string]string
 | 
							RebaseNames map[string]string
 | 
				
			||||||
		InUserNS    bool
 | 
							InUserNS    bool
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Archiver allows the reuse of most utility functions of this package
 | 
					 | 
				
			||||||
	// with a pluggable Untar function. Also, to facilitate the passing of
 | 
					 | 
				
			||||||
	// specific id mappings for untar, an archiver can be created with maps
 | 
					 | 
				
			||||||
	// which will then be passed to Untar operations
 | 
					 | 
				
			||||||
	Archiver struct {
 | 
					 | 
				
			||||||
		Untar   func(io.Reader, string, *TarOptions) error
 | 
					 | 
				
			||||||
		UIDMaps []idtools.IDMap
 | 
					 | 
				
			||||||
		GIDMaps []idtools.IDMap
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// breakoutError is used to differentiate errors related to breaking out
 | 
					 | 
				
			||||||
	// When testing archive breakout in the unit tests, this error is expected
 | 
					 | 
				
			||||||
	// in order for the test to pass.
 | 
					 | 
				
			||||||
	breakoutError error
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					// Archiver allows the reuse of most utility functions of this package
 | 
				
			||||||
	// ErrNotImplemented is the error message of function not implemented.
 | 
					// with a pluggable Untar function. Also, to facilitate the passing of
 | 
				
			||||||
	ErrNotImplemented = errors.New("Function not implemented")
 | 
					// specific id mappings for untar, an archiver can be created with maps
 | 
				
			||||||
	defaultArchiver   = &Archiver{Untar: Untar, UIDMaps: nil, GIDMaps: nil}
 | 
					// which will then be passed to Untar operations
 | 
				
			||||||
)
 | 
					type Archiver struct {
 | 
				
			||||||
 | 
						Untar      func(io.Reader, string, *TarOptions) error
 | 
				
			||||||
 | 
						IDMappings *idtools.IDMappings
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					// NewDefaultArchiver returns a new Archiver without any IDMappings
 | 
				
			||||||
	// HeaderSize is the size in bytes of a tar header
 | 
					func NewDefaultArchiver() *Archiver {
 | 
				
			||||||
	HeaderSize = 512
 | 
						return &Archiver{Untar: Untar, IDMappings: &idtools.IDMappings{}}
 | 
				
			||||||
)
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// breakoutError is used to differentiate errors related to breaking out
 | 
				
			||||||
 | 
					// When testing archive breakout in the unit tests, this error is expected
 | 
				
			||||||
 | 
					// in order for the test to pass.
 | 
				
			||||||
 | 
					type breakoutError error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	// Uncompressed represents the uncompressed.
 | 
						// Uncompressed represents the uncompressed.
 | 
				
			||||||
| 
						 | 
					@ -105,18 +93,6 @@ const (
 | 
				
			||||||
	OverlayWhiteoutFormat
 | 
						OverlayWhiteoutFormat
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// IsArchive checks for the magic bytes of a tar or any supported compression
 | 
					 | 
				
			||||||
// algorithm.
 | 
					 | 
				
			||||||
func IsArchive(header []byte) bool {
 | 
					 | 
				
			||||||
	compression := DetectCompression(header)
 | 
					 | 
				
			||||||
	if compression != Uncompressed {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	r := tar.NewReader(bytes.NewBuffer(header))
 | 
					 | 
				
			||||||
	_, err := r.Next()
 | 
					 | 
				
			||||||
	return err == nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// IsArchivePath checks if the (possibly compressed) file at the given path
 | 
					// IsArchivePath checks if the (possibly compressed) file at the given path
 | 
				
			||||||
// starts with a tar file header.
 | 
					// starts with a tar file header.
 | 
				
			||||||
func IsArchivePath(path string) bool {
 | 
					func IsArchivePath(path string) bool {
 | 
				
			||||||
| 
						 | 
					@ -496,7 +472,7 @@ func (ta *tarAppender) addTarFile(path, name string) error {
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool, chownOpts *TarChownOptions, inUserns bool) error {
 | 
					func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool, chownOpts *idtools.IDPair, inUserns bool) error {
 | 
				
			||||||
	// hdr.Mode is in linux format, which we can use for sycalls,
 | 
						// hdr.Mode is in linux format, which we can use for sycalls,
 | 
				
			||||||
	// but for os.Foo() calls we need the mode converted to os.FileMode,
 | 
						// but for os.Foo() calls we need the mode converted to os.FileMode,
 | 
				
			||||||
	// so use hdrInfo.Mode() (they differ for e.g. setuid bits)
 | 
						// so use hdrInfo.Mode() (they differ for e.g. setuid bits)
 | 
				
			||||||
| 
						 | 
					@ -576,7 +552,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
 | 
				
			||||||
	// Lchown is not supported on Windows.
 | 
						// Lchown is not supported on Windows.
 | 
				
			||||||
	if Lchown && runtime.GOOS != "windows" {
 | 
						if Lchown && runtime.GOOS != "windows" {
 | 
				
			||||||
		if chownOpts == nil {
 | 
							if chownOpts == nil {
 | 
				
			||||||
			chownOpts = &TarChownOptions{UID: hdr.Uid, GID: hdr.Gid}
 | 
								chownOpts = &idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil {
 | 
							if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
| 
						 | 
					@ -941,7 +917,7 @@ loop:
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if err := createTarFile(path, dest, hdr, trBuf, !options.NoLchown, options.ChownOpts, options.InUserNS); err != nil {
 | 
							if err := createTarFile(path, dest, hdr, trBuf, !options.NoLchown, &options.ChownOpts, options.InUserNS); err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1013,23 +989,13 @@ func (archiver *Archiver) TarUntar(src, dst string) error {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer archive.Close()
 | 
						defer archive.Close()
 | 
				
			||||||
 | 
						options := &TarOptions{
 | 
				
			||||||
	var options *TarOptions
 | 
							UIDMaps: archiver.IDMappings.UIDs(),
 | 
				
			||||||
	if archiver.UIDMaps != nil || archiver.GIDMaps != nil {
 | 
							GIDMaps: archiver.IDMappings.GIDs(),
 | 
				
			||||||
		options = &TarOptions{
 | 
					 | 
				
			||||||
			UIDMaps: archiver.UIDMaps,
 | 
					 | 
				
			||||||
			GIDMaps: archiver.GIDMaps,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return archiver.Untar(archive, dst, options)
 | 
						return archiver.Untar(archive, dst, 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 TarUntar(src, dst string) error {
 | 
					 | 
				
			||||||
	return defaultArchiver.TarUntar(src, dst)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// UntarPath untar a file from path to a destination, src is the source tar file path.
 | 
					// 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)
 | 
				
			||||||
| 
						 | 
					@ -1037,22 +1003,13 @@ func (archiver *Archiver) UntarPath(src, dst string) error {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer archive.Close()
 | 
						defer archive.Close()
 | 
				
			||||||
	var options *TarOptions
 | 
						options := &TarOptions{
 | 
				
			||||||
	if archiver.UIDMaps != nil || archiver.GIDMaps != nil {
 | 
							UIDMaps: archiver.IDMappings.UIDs(),
 | 
				
			||||||
		options = &TarOptions{
 | 
							GIDMaps: archiver.IDMappings.GIDs(),
 | 
				
			||||||
			UIDMaps: archiver.UIDMaps,
 | 
					 | 
				
			||||||
			GIDMaps: archiver.GIDMaps,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return archiver.Untar(archive, dst, options)
 | 
						return archiver.Untar(archive, dst, options)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UntarPath is a convenience function which looks for an archive
 | 
					 | 
				
			||||||
// at filesystem path `src`, and unpacks it at `dst`.
 | 
					 | 
				
			||||||
func UntarPath(src, dst string) error {
 | 
					 | 
				
			||||||
	return defaultArchiver.UntarPath(src, dst)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// CopyWithTar creates a tar archive of filesystem path `src`, and
 | 
					// CopyWithTar creates a tar archive of filesystem path `src`, and
 | 
				
			||||||
// unpacks it at filesystem path `dst`.
 | 
					// unpacks it at filesystem path `dst`.
 | 
				
			||||||
// The archive is streamed directly with fixed buffering and no
 | 
					// The archive is streamed directly with fixed buffering and no
 | 
				
			||||||
| 
						 | 
					@ -1069,27 +1026,19 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
 | 
				
			||||||
	// if this archiver is set up with ID mapping we need to create
 | 
						// if this archiver is set up with ID mapping we need to create
 | 
				
			||||||
	// the new destination directory with the remapped root UID/GID pair
 | 
						// the new destination directory with the remapped root UID/GID pair
 | 
				
			||||||
	// as owner
 | 
						// as owner
 | 
				
			||||||
	rootUID, rootGID, err := idtools.GetRootUIDGID(archiver.UIDMaps, archiver.GIDMaps)
 | 
						rootIDs, err := archiver.IDMappings.RootPair()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Create dst, copy src's content into it
 | 
						// Create dst, copy src's content into it
 | 
				
			||||||
	logrus.Debugf("Creating dest directory: %s", dst)
 | 
						logrus.Debugf("Creating dest directory: %s", dst)
 | 
				
			||||||
	if err := idtools.MkdirAllNewAs(dst, 0755, rootUID, rootGID); err != nil {
 | 
						if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	logrus.Debugf("Calling TarUntar(%s, %s)", src, dst)
 | 
						logrus.Debugf("Calling TarUntar(%s, %s)", src, dst)
 | 
				
			||||||
	return archiver.TarUntar(src, dst)
 | 
						return archiver.TarUntar(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 CopyWithTar(src, dst string) error {
 | 
					 | 
				
			||||||
	return defaultArchiver.CopyWithTar(src, dst)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// CopyFileWithTar emulates the behavior of the 'cp' command-line
 | 
					// CopyFileWithTar emulates the behavior of the 'cp' command-line
 | 
				
			||||||
// for a single file. It copies a regular file from path `src` to
 | 
					// for a single file. It copies a regular file from path `src` to
 | 
				
			||||||
// path `dst`, and preserves all its metadata.
 | 
					// path `dst`, and preserves all its metadata.
 | 
				
			||||||
| 
						 | 
					@ -1131,26 +1080,24 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
 | 
				
			||||||
		hdr.Name = filepath.Base(dst)
 | 
							hdr.Name = filepath.Base(dst)
 | 
				
			||||||
		hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))
 | 
							hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		remappedRootUID, remappedRootGID, err := idtools.GetRootUIDGID(archiver.UIDMaps, archiver.GIDMaps)
 | 
							remappedRootIDs, err := archiver.IDMappings.RootPair()
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// only perform mapping if the file being copied isn't already owned by the
 | 
							// only perform mapping if the file being copied isn't already owned by the
 | 
				
			||||||
		// uid or gid of the remapped root in the container
 | 
							// uid or gid of the remapped root in the container
 | 
				
			||||||
		if remappedRootUID != hdr.Uid {
 | 
							if remappedRootIDs.UID != hdr.Uid {
 | 
				
			||||||
			xUID, err := idtools.ToHost(hdr.Uid, archiver.UIDMaps)
 | 
								hdr.Uid, err = archiver.IDMappings.UIDToHost(hdr.Uid)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			hdr.Uid = xUID
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if remappedRootGID != hdr.Gid {
 | 
							if remappedRootIDs.GID != hdr.Gid {
 | 
				
			||||||
			xGID, err := idtools.ToHost(hdr.Gid, archiver.GIDMaps)
 | 
								hdr.Gid, err = archiver.IDMappings.GIDToHost(hdr.Gid)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			hdr.Gid = xGID
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		tw := tar.NewWriter(w)
 | 
							tw := tar.NewWriter(w)
 | 
				
			||||||
| 
						 | 
					@ -1176,18 +1123,6 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Destination handling is in an operating specific manner depending
 | 
					 | 
				
			||||||
// where the daemon is running. If `dst` ends with a trailing slash
 | 
					 | 
				
			||||||
// the final destination path will be `dst/base(src)`  (Linux) or
 | 
					 | 
				
			||||||
// `dst\base(src)` (Windows).
 | 
					 | 
				
			||||||
func CopyFileWithTar(src, dst string) (err error) {
 | 
					 | 
				
			||||||
	return defaultArchiver.CopyFileWithTar(src, dst)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// cmdStream executes a command, and returns its stdout as a stream.
 | 
					// cmdStream executes a command, and returns its stdout as a stream.
 | 
				
			||||||
// If the command fails to run or doesn't complete successfully, an error
 | 
					// If the command fails to run or doesn't complete successfully, an error
 | 
				
			||||||
// will be returned, including anything written on stderr.
 | 
					// will be returned, including anything written on stderr.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,35 +27,22 @@ func init() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestIsArchiveNilHeader(t *testing.T) {
 | 
					var defaultArchiver = NewDefaultArchiver()
 | 
				
			||||||
	out := IsArchive(nil)
 | 
					
 | 
				
			||||||
	if out {
 | 
					func defaultTarUntar(src, dst string) error {
 | 
				
			||||||
		t.Fatalf("isArchive should return false as nil is not a valid archive header")
 | 
						return defaultArchiver.TarUntar(src, dst)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestIsArchiveInvalidHeader(t *testing.T) {
 | 
					func defaultUntarPath(src, dst string) error {
 | 
				
			||||||
	header := []byte{0x00, 0x01, 0x02}
 | 
						return defaultArchiver.UntarPath(src, dst)
 | 
				
			||||||
	out := IsArchive(header)
 | 
					 | 
				
			||||||
	if out {
 | 
					 | 
				
			||||||
		t.Fatalf("isArchive should return false as %s is not a valid archive header", header)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestIsArchiveBzip2(t *testing.T) {
 | 
					func defaultCopyFileWithTar(src, dst string) (err error) {
 | 
				
			||||||
	header := []byte{0x42, 0x5A, 0x68}
 | 
						return defaultArchiver.CopyFileWithTar(src, dst)
 | 
				
			||||||
	out := IsArchive(header)
 | 
					 | 
				
			||||||
	if !out {
 | 
					 | 
				
			||||||
		t.Fatalf("isArchive should return true as %s is a bz2 header", header)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestIsArchive7zip(t *testing.T) {
 | 
					func defaultCopyWithTar(src, dst string) error {
 | 
				
			||||||
	header := []byte{0x50, 0x4b, 0x03, 0x04}
 | 
						return defaultArchiver.CopyWithTar(src, dst)
 | 
				
			||||||
	out := IsArchive(header)
 | 
					 | 
				
			||||||
	if out {
 | 
					 | 
				
			||||||
		t.Fatalf("isArchive should return false as %s is a 7z header and it is not supported", header)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestIsArchivePathDir(t *testing.T) {
 | 
					func TestIsArchivePathDir(t *testing.T) {
 | 
				
			||||||
| 
						 | 
					@ -301,7 +288,7 @@ func TestUntarPathWithInvalidDest(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = UntarPath(tarFile, invalidDestFolder)
 | 
						err = defaultUntarPath(tarFile, invalidDestFolder)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("UntarPath with invalid destination path should throw an error.")
 | 
							t.Fatalf("UntarPath with invalid destination path should throw an error.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -313,7 +300,7 @@ func TestUntarPathWithInvalidSrc(t *testing.T) {
 | 
				
			||||||
		t.Fatalf("Fail to create the destination file")
 | 
							t.Fatalf("Fail to create the destination file")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer os.RemoveAll(dest)
 | 
						defer os.RemoveAll(dest)
 | 
				
			||||||
	err = UntarPath("/invalid/path", dest)
 | 
						err = defaultUntarPath("/invalid/path", dest)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("UntarPath with invalid src path should throw an error.")
 | 
							t.Fatalf("UntarPath with invalid src path should throw an error.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -348,7 +335,7 @@ func TestUntarPath(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = UntarPath(tarFile, destFolder)
 | 
						err = defaultUntarPath(tarFile, destFolder)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("UntarPath shouldn't throw an error, %s.", err)
 | 
							t.Fatalf("UntarPath shouldn't throw an error, %s.", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -387,7 +374,7 @@ func TestUntarPathWithDestinationFile(t *testing.T) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Fail to create the destination file")
 | 
							t.Fatalf("Fail to create the destination file")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = UntarPath(tarFile, destFile)
 | 
						err = defaultUntarPath(tarFile, destFile)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("UntarPath should throw an error if the destination if a file")
 | 
							t.Fatalf("UntarPath should throw an error if the destination if a file")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -430,7 +417,7 @@ func TestUntarPathWithDestinationSrcFileAsFolder(t *testing.T) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = UntarPath(tarFile, destFolder)
 | 
						err = defaultUntarPath(tarFile, destFolder)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("UntarPath should throw not throw an error if the extracted file already exists and is a folder")
 | 
							t.Fatalf("UntarPath should throw not throw an error if the extracted file already exists and is a folder")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -447,7 +434,7 @@ func TestCopyWithTarInvalidSrc(t *testing.T) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = CopyWithTar(invalidSrc, destFolder)
 | 
						err = defaultCopyWithTar(invalidSrc, destFolder)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("archiver.CopyWithTar with invalid src path should throw an error.")
 | 
							t.Fatalf("archiver.CopyWithTar with invalid src path should throw an error.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -464,7 +451,7 @@ func TestCopyWithTarInexistentDestWillCreateIt(t *testing.T) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = CopyWithTar(srcFolder, inexistentDestFolder)
 | 
						err = defaultCopyWithTar(srcFolder, inexistentDestFolder)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("CopyWithTar with an inexistent folder shouldn't fail.")
 | 
							t.Fatalf("CopyWithTar with an inexistent folder shouldn't fail.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -493,7 +480,7 @@ func TestCopyWithTarSrcFile(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ioutil.WriteFile(src, []byte("content"), 0777)
 | 
						ioutil.WriteFile(src, []byte("content"), 0777)
 | 
				
			||||||
	err = CopyWithTar(src, dest)
 | 
						err = defaultCopyWithTar(src, dest)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err)
 | 
							t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -522,7 +509,7 @@ func TestCopyWithTarSrcFolder(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ioutil.WriteFile(filepath.Join(src, "file"), []byte("content"), 0777)
 | 
						ioutil.WriteFile(filepath.Join(src, "file"), []byte("content"), 0777)
 | 
				
			||||||
	err = CopyWithTar(src, dest)
 | 
						err = defaultCopyWithTar(src, dest)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err)
 | 
							t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -545,7 +532,7 @@ func TestCopyFileWithTarInvalidSrc(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	invalidFile := filepath.Join(tempFolder, "doesnotexists")
 | 
						invalidFile := filepath.Join(tempFolder, "doesnotexists")
 | 
				
			||||||
	err = CopyFileWithTar(invalidFile, destFolder)
 | 
						err = defaultCopyFileWithTar(invalidFile, destFolder)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("archiver.CopyWithTar with invalid src path should throw an error.")
 | 
							t.Fatalf("archiver.CopyWithTar with invalid src path should throw an error.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -563,7 +550,7 @@ func TestCopyFileWithTarInexistentDestWillCreateIt(t *testing.T) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = CopyFileWithTar(srcFile, inexistentDestFolder)
 | 
						err = defaultCopyFileWithTar(srcFile, inexistentDestFolder)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("CopyWithTar with an inexistent folder shouldn't fail.")
 | 
							t.Fatalf("CopyWithTar with an inexistent folder shouldn't fail.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -590,7 +577,7 @@ func TestCopyFileWithTarSrcFolder(t *testing.T) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = CopyFileWithTar(src, dest)
 | 
						err = defaultCopyFileWithTar(src, dest)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("CopyFileWithTar should throw an error with a folder.")
 | 
							t.Fatalf("CopyFileWithTar should throw an error with a folder.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -614,7 +601,7 @@ func TestCopyFileWithTarSrcFile(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ioutil.WriteFile(src, []byte("content"), 0777)
 | 
						ioutil.WriteFile(src, []byte("content"), 0777)
 | 
				
			||||||
	err = CopyWithTar(src, dest+"/")
 | 
						err = defaultCopyWithTar(src, dest+"/")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("archiver.CopyFileWithTar shouldn't throw an error, %s.", err)
 | 
							t.Fatalf("archiver.CopyFileWithTar shouldn't throw an error, %s.", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -657,7 +644,7 @@ func checkNoChanges(fileNum int, hardlinks bool) error {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = TarUntar(srcDir, destDir)
 | 
						err = defaultTarUntar(srcDir, destDir)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -871,7 +858,7 @@ func BenchmarkTarUntar(b *testing.B) {
 | 
				
			||||||
	b.ResetTimer()
 | 
						b.ResetTimer()
 | 
				
			||||||
	b.SetBytes(int64(n))
 | 
						b.SetBytes(int64(n))
 | 
				
			||||||
	for n := 0; n < b.N; n++ {
 | 
						for n := 0; n < b.N; n++ {
 | 
				
			||||||
		err := TarUntar(origin, target)
 | 
							err := defaultTarUntar(origin, target)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			b.Fatal(err)
 | 
								b.Fatal(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -899,7 +886,7 @@ func BenchmarkTarUntarWithLinks(b *testing.B) {
 | 
				
			||||||
	b.ResetTimer()
 | 
						b.ResetTimer()
 | 
				
			||||||
	b.SetBytes(int64(n))
 | 
						b.SetBytes(int64(n))
 | 
				
			||||||
	for n := 0; n < b.N; n++ {
 | 
						for n := 0; n < b.N; n++ {
 | 
				
			||||||
		err := TarUntar(origin, target)
 | 
							err := defaultTarUntar(origin, target)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			b.Fatal(err)
 | 
								b.Fatal(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ func TestCopyFileWithInvalidDest(t *testing.T) {
 | 
				
			||||||
		t.Fatal(err)
 | 
							t.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ioutil.WriteFile(src, []byte("content"), 0777)
 | 
						ioutil.WriteFile(src, []byte("content"), 0777)
 | 
				
			||||||
	err = CopyWithTar(src, dest)
 | 
						err = defaultCopyWithTar(src, dest)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.")
 | 
							t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,13 @@ import (
 | 
				
			||||||
	"github.com/docker/docker/pkg/idtools"
 | 
						"github.com/docker/docker/pkg/idtools"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var chrootArchiver = &archive.Archiver{Untar: Untar}
 | 
					// NewArchiver returns a new Archiver which uses chrootarchive.Untar
 | 
				
			||||||
 | 
					func NewArchiver(idMappings *idtools.IDMappings) *archive.Archiver {
 | 
				
			||||||
 | 
						if idMappings == nil {
 | 
				
			||||||
 | 
							idMappings = &idtools.IDMappings{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return &archive.Archiver{Untar: Untar, IDMappings: idMappings}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Untar reads a stream of bytes from `archive`, parses it as a tar archive,
 | 
					// Untar 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`.
 | 
				
			||||||
| 
						 | 
					@ -30,7 +36,6 @@ func UntarUncompressed(tarArchive io.Reader, dest string, options *archive.TarOp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handler for teasing out the automatic decompression
 | 
					// Handler for teasing out the automatic decompression
 | 
				
			||||||
func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions, decompress bool) error {
 | 
					func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions, decompress bool) error {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if tarArchive == nil {
 | 
						if tarArchive == nil {
 | 
				
			||||||
		return fmt.Errorf("Empty archive")
 | 
							return fmt.Errorf("Empty archive")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -65,33 +70,3 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return invokeUnpack(r, dest, options)
 | 
						return invokeUnpack(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 TarUntar(src, dst string) error {
 | 
					 | 
				
			||||||
	return chrootArchiver.TarUntar(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 CopyWithTar(src, dst string) error {
 | 
					 | 
				
			||||||
	return chrootArchiver.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.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// If `dst` ends with a trailing slash '/' ('\' on Windows), the final
 | 
					 | 
				
			||||||
// destination path will be `dst/base(src)` or `dst\base(src)`
 | 
					 | 
				
			||||||
func CopyFileWithTar(src, dst string) (err error) {
 | 
					 | 
				
			||||||
	return chrootArchiver.CopyFileWithTar(src, dst)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// UntarPath is a convenience function which looks for an archive
 | 
					 | 
				
			||||||
// at filesystem path `src`, and unpacks it at `dst`.
 | 
					 | 
				
			||||||
func UntarPath(src, dst string) error {
 | 
					 | 
				
			||||||
	return chrootArchiver.UntarPath(src, dst)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,24 @@ func init() {
 | 
				
			||||||
	reexec.Init()
 | 
						reexec.Init()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var chrootArchiver = NewArchiver(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TarUntar(src, dst string) error {
 | 
				
			||||||
 | 
						return chrootArchiver.TarUntar(src, dst)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func CopyFileWithTar(src, dst string) (err error) {
 | 
				
			||||||
 | 
						return chrootArchiver.CopyFileWithTar(src, dst)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func UntarPath(src, dst string) error {
 | 
				
			||||||
 | 
						return chrootArchiver.UntarPath(src, dst)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func CopyWithTar(src, dst string) error {
 | 
				
			||||||
 | 
						return chrootArchiver.CopyWithTar(src, dst)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestChrootTarUntar(t *testing.T) {
 | 
					func TestChrootTarUntar(t *testing.T) {
 | 
				
			||||||
	tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar")
 | 
						tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,6 +118,7 @@ func ToContainer(hostID int, idMap []IDMap) (int, error) {
 | 
				
			||||||
// ToHost takes an id mapping and a remapped ID, and translates the
 | 
					// ToHost takes an id mapping and a remapped ID, and translates the
 | 
				
			||||||
// ID to the mapped host ID. If no map is provided, then the translation
 | 
					// ID to the mapped host ID. If no map is provided, then the translation
 | 
				
			||||||
// assumes a 1-to-1 mapping and returns the passed in id #
 | 
					// assumes a 1-to-1 mapping and returns the passed in id #
 | 
				
			||||||
 | 
					// Depercated: use IDMappings.UIDToHost and IDMappings.GIDToHost
 | 
				
			||||||
func ToHost(contID int, idMap []IDMap) (int, error) {
 | 
					func ToHost(contID int, idMap []IDMap) (int, error) {
 | 
				
			||||||
	if idMap == nil {
 | 
						if idMap == nil {
 | 
				
			||||||
		return contID, nil
 | 
							return contID, nil
 | 
				
			||||||
| 
						 | 
					@ -174,6 +175,16 @@ func (i *IDMappings) RootPair() (IDPair, error) {
 | 
				
			||||||
	return IDPair{UID: uid, GID: gid}, err
 | 
						return IDPair{UID: uid, GID: gid}, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UIDToHost returns the host UID for the container uid
 | 
				
			||||||
 | 
					func (i *IDMappings) UIDToHost(uid int) (int, error) {
 | 
				
			||||||
 | 
						return ToHost(uid, i.uids)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GIDToHost returns the host GID for the container gid
 | 
				
			||||||
 | 
					func (i *IDMappings) GIDToHost(gid int) (int, error) {
 | 
				
			||||||
 | 
						return ToHost(gid, i.gids)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UIDs return the UID mapping
 | 
					// UIDs return the UID mapping
 | 
				
			||||||
// TODO: remove this once everything has been refactored to use pairs
 | 
					// TODO: remove this once everything has been refactored to use pairs
 | 
				
			||||||
func (i *IDMappings) UIDs() []IDMap {
 | 
					func (i *IDMappings) UIDs() []IDMap {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue