|
@@ -52,7 +52,7 @@ type (
|
|
NoLchown bool
|
|
NoLchown bool
|
|
UIDMaps []idtools.IDMap
|
|
UIDMaps []idtools.IDMap
|
|
GIDMaps []idtools.IDMap
|
|
GIDMaps []idtools.IDMap
|
|
- ChownOpts *idtools.IDPair
|
|
|
|
|
|
+ ChownOpts *idtools.Identity
|
|
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
|
|
@@ -72,13 +72,13 @@ type (
|
|
// this package with a pluggable Untar function. Also, to facilitate the passing of specific id
|
|
// 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.
|
|
// mappings for untar, an Archiver can be created with maps which will then be passed to Untar operations.
|
|
type Archiver struct {
|
|
type Archiver struct {
|
|
- Untar func(io.Reader, string, *TarOptions) error
|
|
|
|
- IDMappingsVar *idtools.IDMappings
|
|
|
|
|
|
+ Untar func(io.Reader, string, *TarOptions) error
|
|
|
|
+ IDMapping *idtools.IdentityMapping
|
|
}
|
|
}
|
|
|
|
|
|
-// NewDefaultArchiver returns a new Archiver without any IDMappings
|
|
|
|
|
|
+// NewDefaultArchiver returns a new Archiver without any IdentityMapping
|
|
func NewDefaultArchiver() *Archiver {
|
|
func NewDefaultArchiver() *Archiver {
|
|
- return &Archiver{Untar: Untar, IDMappingsVar: &idtools.IDMappings{}}
|
|
|
|
|
|
+ return &Archiver{Untar: Untar, IDMapping: &idtools.IdentityMapping{}}
|
|
}
|
|
}
|
|
|
|
|
|
// breakoutError is used to differentiate errors related to breaking out
|
|
// breakoutError is used to differentiate errors related to breaking out
|
|
@@ -420,9 +420,9 @@ type tarAppender struct {
|
|
Buffer *bufio.Writer
|
|
Buffer *bufio.Writer
|
|
|
|
|
|
// for hardlink mapping
|
|
// for hardlink mapping
|
|
- SeenFiles map[uint64]string
|
|
|
|
- IDMappings *idtools.IDMappings
|
|
|
|
- ChownOpts *idtools.IDPair
|
|
|
|
|
|
+ SeenFiles map[uint64]string
|
|
|
|
+ IdentityMapping *idtools.IdentityMapping
|
|
|
|
+ ChownOpts *idtools.Identity
|
|
|
|
|
|
// For packing and unpacking whiteout files in the
|
|
// For packing and unpacking whiteout files in the
|
|
// non standard format. The whiteout files defined
|
|
// non standard format. The whiteout files defined
|
|
@@ -431,13 +431,13 @@ type tarAppender struct {
|
|
WhiteoutConverter tarWhiteoutConverter
|
|
WhiteoutConverter tarWhiteoutConverter
|
|
}
|
|
}
|
|
|
|
|
|
-func newTarAppender(idMapping *idtools.IDMappings, writer io.Writer, chownOpts *idtools.IDPair) *tarAppender {
|
|
|
|
|
|
+func newTarAppender(idMapping *idtools.IdentityMapping, writer io.Writer, chownOpts *idtools.Identity) *tarAppender {
|
|
return &tarAppender{
|
|
return &tarAppender{
|
|
- SeenFiles: make(map[uint64]string),
|
|
|
|
- TarWriter: tar.NewWriter(writer),
|
|
|
|
- Buffer: pools.BufioWriter32KPool.Get(nil),
|
|
|
|
- IDMappings: idMapping,
|
|
|
|
- ChownOpts: chownOpts,
|
|
|
|
|
|
+ SeenFiles: make(map[uint64]string),
|
|
|
|
+ TarWriter: tar.NewWriter(writer),
|
|
|
|
+ Buffer: pools.BufioWriter32KPool.Get(nil),
|
|
|
|
+ IdentityMapping: idMapping,
|
|
|
|
+ ChownOpts: chownOpts,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -502,14 +502,12 @@ func (ta *tarAppender) addTarFile(path, name string) error {
|
|
//handle re-mapping container ID mappings back to host ID mappings before
|
|
//handle re-mapping container ID mappings back to host ID mappings before
|
|
//writing tar headers/files. We skip whiteout files because they were written
|
|
//writing tar headers/files. We skip whiteout files because they were written
|
|
//by the kernel and already have proper ownership relative to the host
|
|
//by the kernel and already have proper ownership relative to the host
|
|
- if !isOverlayWhiteout &&
|
|
|
|
- !strings.HasPrefix(filepath.Base(hdr.Name), WhiteoutPrefix) &&
|
|
|
|
- !ta.IDMappings.Empty() {
|
|
|
|
|
|
+ if !isOverlayWhiteout && !strings.HasPrefix(filepath.Base(hdr.Name), WhiteoutPrefix) && !ta.IdentityMapping.Empty() {
|
|
fileIDPair, err := getFileUIDGID(fi.Sys())
|
|
fileIDPair, err := getFileUIDGID(fi.Sys())
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- hdr.Uid, hdr.Gid, err = ta.IDMappings.ToContainer(fileIDPair)
|
|
|
|
|
|
+ hdr.Uid, hdr.Gid, err = ta.IdentityMapping.ToContainer(fileIDPair)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -572,7 +570,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 *idtools.IDPair, inUserns bool) error {
|
|
|
|
|
|
+func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool, chownOpts *idtools.Identity, 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)
|
|
@@ -652,7 +650,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 = &idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid}
|
|
|
|
|
|
+ chownOpts = &idtools.Identity{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
|
|
@@ -901,8 +899,8 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err
|
|
defer pools.BufioReader32KPool.Put(trBuf)
|
|
defer pools.BufioReader32KPool.Put(trBuf)
|
|
|
|
|
|
var dirs []*tar.Header
|
|
var dirs []*tar.Header
|
|
- idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
|
|
|
|
- rootIDs := idMappings.RootPair()
|
|
|
|
|
|
+ idMapping := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
|
|
|
|
+ rootIDs := idMapping.RootPair()
|
|
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
|
|
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
|
|
|
|
|
|
// Iterate through the files in the archive.
|
|
// Iterate through the files in the archive.
|
|
@@ -981,7 +979,7 @@ loop:
|
|
}
|
|
}
|
|
trBuf.Reset(tr)
|
|
trBuf.Reset(tr)
|
|
|
|
|
|
- if err := remapIDs(idMappings, hdr); err != nil {
|
|
|
|
|
|
+ if err := remapIDs(idMapping, hdr); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1068,8 +1066,8 @@ func (archiver *Archiver) TarUntar(src, dst string) error {
|
|
}
|
|
}
|
|
defer archive.Close()
|
|
defer archive.Close()
|
|
options := &TarOptions{
|
|
options := &TarOptions{
|
|
- UIDMaps: archiver.IDMappingsVar.UIDs(),
|
|
|
|
- GIDMaps: archiver.IDMappingsVar.GIDs(),
|
|
|
|
|
|
+ UIDMaps: archiver.IDMapping.UIDs(),
|
|
|
|
+ GIDMaps: archiver.IDMapping.GIDs(),
|
|
}
|
|
}
|
|
return archiver.Untar(archive, dst, options)
|
|
return archiver.Untar(archive, dst, options)
|
|
}
|
|
}
|
|
@@ -1082,8 +1080,8 @@ func (archiver *Archiver) UntarPath(src, dst string) error {
|
|
}
|
|
}
|
|
defer archive.Close()
|
|
defer archive.Close()
|
|
options := &TarOptions{
|
|
options := &TarOptions{
|
|
- UIDMaps: archiver.IDMappingsVar.UIDs(),
|
|
|
|
- GIDMaps: archiver.IDMappingsVar.GIDs(),
|
|
|
|
|
|
+ UIDMaps: archiver.IDMapping.UIDs(),
|
|
|
|
+ GIDMaps: archiver.IDMapping.GIDs(),
|
|
}
|
|
}
|
|
return archiver.Untar(archive, dst, options)
|
|
return archiver.Untar(archive, dst, options)
|
|
}
|
|
}
|
|
@@ -1104,7 +1102,7 @@ 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
|
|
- rootIDs := archiver.IDMappingsVar.RootPair()
|
|
|
|
|
|
+ rootIDs := archiver.IDMapping.RootPair()
|
|
// 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.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
|
|
if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
|
|
@@ -1164,7 +1162,7 @@ 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)))
|
|
|
|
|
|
- if err := remapIDs(archiver.IDMappingsVar, hdr); err != nil {
|
|
|
|
|
|
+ if err := remapIDs(archiver.IDMapping, hdr); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1192,13 +1190,13 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
-// IDMappings returns the IDMappings of the archiver.
|
|
|
|
-func (archiver *Archiver) IDMappings() *idtools.IDMappings {
|
|
|
|
- return archiver.IDMappingsVar
|
|
|
|
|
|
+// IdentityMapping returns the IdentityMapping of the archiver.
|
|
|
|
+func (archiver *Archiver) IdentityMapping() *idtools.IdentityMapping {
|
|
|
|
+ return archiver.IDMapping
|
|
}
|
|
}
|
|
|
|
|
|
-func remapIDs(idMappings *idtools.IDMappings, hdr *tar.Header) error {
|
|
|
|
- ids, err := idMappings.ToHost(idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid})
|
|
|
|
|
|
+func remapIDs(idMapping *idtools.IdentityMapping, hdr *tar.Header) error {
|
|
|
|
+ ids, err := idMapping.ToHost(idtools.Identity{UID: hdr.Uid, GID: hdr.Gid})
|
|
hdr.Uid, hdr.Gid = ids.UID, ids.GID
|
|
hdr.Uid, hdr.Gid = ids.UID, ids.GID
|
|
return err
|
|
return err
|
|
}
|
|
}
|