|
@@ -345,9 +345,8 @@ type tarAppender struct {
|
|
Buffer *bufio.Writer
|
|
Buffer *bufio.Writer
|
|
|
|
|
|
// for hardlink mapping
|
|
// for hardlink mapping
|
|
- SeenFiles map[uint64]string
|
|
|
|
- UIDMaps []idtools.IDMap
|
|
|
|
- GIDMaps []idtools.IDMap
|
|
|
|
|
|
+ SeenFiles map[uint64]string
|
|
|
|
+ IDMappings *idtools.IDMappings
|
|
|
|
|
|
// 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
|
|
@@ -356,6 +355,15 @@ type tarAppender struct {
|
|
WhiteoutConverter tarWhiteoutConverter
|
|
WhiteoutConverter tarWhiteoutConverter
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func newTarAppender(idMapping *idtools.IDMappings, writer io.Writer) *tarAppender {
|
|
|
|
+ return &tarAppender{
|
|
|
|
+ SeenFiles: make(map[uint64]string),
|
|
|
|
+ TarWriter: tar.NewWriter(writer),
|
|
|
|
+ Buffer: pools.BufioWriter32KPool.Get(nil),
|
|
|
|
+ IDMappings: idMapping,
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// canonicalTarName provides a platform-independent and consistent posix-style
|
|
// canonicalTarName provides a platform-independent and consistent posix-style
|
|
//path for files and directories to be archived regardless of the platform.
|
|
//path for files and directories to be archived regardless of the platform.
|
|
func canonicalTarName(name string, isDir bool) (string, error) {
|
|
func canonicalTarName(name string, isDir bool) (string, error) {
|
|
@@ -404,21 +412,19 @@ 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 !strings.HasPrefix(filepath.Base(hdr.Name), WhiteoutPrefix) && (ta.UIDMaps != nil || ta.GIDMaps != nil) {
|
|
|
|
|
|
+ if !strings.HasPrefix(filepath.Base(hdr.Name), WhiteoutPrefix) && !ta.IDMappings.Empty() {
|
|
uid, gid, err := getFileUIDGID(fi.Sys())
|
|
uid, gid, err := getFileUIDGID(fi.Sys())
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- xUID, err := idtools.ToContainer(uid, ta.UIDMaps)
|
|
|
|
|
|
+ hdr.Uid, err = ta.IDMappings.UIDToContainer(uid)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- xGID, err := idtools.ToContainer(gid, ta.GIDMaps)
|
|
|
|
|
|
+ hdr.Gid, err = ta.IDMappings.GIDToContainer(gid)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- hdr.Uid = xUID
|
|
|
|
- hdr.Gid = xGID
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if ta.WhiteoutConverter != nil {
|
|
if ta.WhiteoutConverter != nil {
|
|
@@ -640,14 +646,11 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
|
|
}
|
|
}
|
|
|
|
|
|
go func() {
|
|
go func() {
|
|
- ta := &tarAppender{
|
|
|
|
- TarWriter: tar.NewWriter(compressWriter),
|
|
|
|
- Buffer: pools.BufioWriter32KPool.Get(nil),
|
|
|
|
- SeenFiles: make(map[uint64]string),
|
|
|
|
- UIDMaps: options.UIDMaps,
|
|
|
|
- GIDMaps: options.GIDMaps,
|
|
|
|
- WhiteoutConverter: getWhiteoutConverter(options.WhiteoutFormat),
|
|
|
|
- }
|
|
|
|
|
|
+ ta := newTarAppender(
|
|
|
|
+ idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps),
|
|
|
|
+ compressWriter,
|
|
|
|
+ )
|
|
|
|
+ ta.WhiteoutConverter = getWhiteoutConverter(options.WhiteoutFormat)
|
|
|
|
|
|
defer func() {
|
|
defer func() {
|
|
// Make sure to check the error on Close.
|
|
// Make sure to check the error on Close.
|