github.com/containers/storage v1.12.13

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2019-08-01 03:46:14 -04:00
parent 39de184b8b
commit 9d6dce1199
191 changed files with 15069 additions and 59037 deletions

View File

@@ -36,14 +36,15 @@ type (
// TarOptions wraps the tar options.
TarOptions struct {
IncludeFiles []string
ExcludePatterns []string
Compression Compression
NoLchown bool
UIDMaps []idtools.IDMap
GIDMaps []idtools.IDMap
ChownOpts *idtools.IDPair
IncludeSourceDir bool
IncludeFiles []string
ExcludePatterns []string
Compression Compression
NoLchown bool
UIDMaps []idtools.IDMap
GIDMaps []idtools.IDMap
IgnoreChownErrors bool
ChownOpts *idtools.IDPair
IncludeSourceDir bool
// WhiteoutFormat is the expected on disk format for whiteout files.
// This format will be converted to the standard format on pack
// and from the standard format on unpack.
@@ -563,7 +564,7 @@ func (ta *tarAppender) addTarFile(path, name string) error {
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.IDPair, inUserns, ignoreChownErrors bool) error {
// 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,
// so use hdrInfo.Mode() (they differ for e.g. setuid bits)
@@ -645,8 +646,13 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
if chownOpts == nil {
chownOpts = &idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid}
}
if err := idtools.SafeLchown(path, chownOpts.UID, chownOpts.GID); err != nil {
return err
err := idtools.SafeLchown(path, chownOpts.UID, chownOpts.GID)
if err != nil {
if ignoreChownErrors {
fmt.Fprintf(os.Stderr, "Chown error detected. Ignoring due to ignoreChownErrors flag: %v\n", err)
} else {
return err
}
}
}
@@ -993,7 +999,7 @@ loop:
chownOpts = &idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid}
}
if err := createTarFile(path, dest, hdr, trBuf, !options.NoLchown, chownOpts, options.InUserNS); err != nil {
if err := createTarFile(path, dest, hdr, trBuf, !options.NoLchown, chownOpts, options.InUserNS, options.IgnoreChownErrors); err != nil {
return err
}

View File

@@ -1,17 +0,0 @@
// +build cgo
package archive
import (
"io"
"github.com/DataDog/zstd"
)
func zstdReader(buf io.Reader) (io.ReadCloser, error) {
return zstd.NewReader(buf), nil
}
func zstdWriter(dest io.Writer) (io.WriteCloser, error) {
return zstd.NewWriter(dest), nil
}

View File

@@ -445,6 +445,11 @@ func (j *TarOptions) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
} else {
buf.WriteString(`null`)
}
if j.IgnoreChownErrors {
buf.WriteString(`,"IgnoreChownErrors":true`)
} else {
buf.WriteString(`,"IgnoreChownErrors":false`)
}
if j.ChownOpts != nil {
/* Struct fall back. type=idtools.IDPair kind=struct */
buf.WriteString(`,"ChownOpts":`)
@@ -516,6 +521,8 @@ const (
ffjtTarOptionsGIDMaps
ffjtTarOptionsIgnoreChownErrors
ffjtTarOptionsChownOpts
ffjtTarOptionsIncludeSourceDir
@@ -545,6 +552,8 @@ var ffjKeyTarOptionsUIDMaps = []byte("UIDMaps")
var ffjKeyTarOptionsGIDMaps = []byte("GIDMaps")
var ffjKeyTarOptionsIgnoreChownErrors = []byte("IgnoreChownErrors")
var ffjKeyTarOptionsChownOpts = []byte("ChownOpts")
var ffjKeyTarOptionsIncludeSourceDir = []byte("IncludeSourceDir")
@@ -663,6 +672,11 @@ mainparse:
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffjKeyTarOptionsIgnoreChownErrors, kn) {
currentKey = ffjtTarOptionsIgnoreChownErrors
state = fflib.FFParse_want_colon
goto mainparse
} else if bytes.Equal(ffjKeyTarOptionsIncludeSourceDir, kn) {
currentKey = ffjtTarOptionsIncludeSourceDir
state = fflib.FFParse_want_colon
@@ -766,6 +780,12 @@ mainparse:
goto mainparse
}
if fflib.EqualFoldRight(ffjKeyTarOptionsIgnoreChownErrors, kn) {
currentKey = ffjtTarOptionsIgnoreChownErrors
state = fflib.FFParse_want_colon
goto mainparse
}
if fflib.EqualFoldRight(ffjKeyTarOptionsGIDMaps, kn) {
currentKey = ffjtTarOptionsGIDMaps
state = fflib.FFParse_want_colon
@@ -837,6 +857,9 @@ mainparse:
case ffjtTarOptionsGIDMaps:
goto handle_GIDMaps
case ffjtTarOptionsIgnoreChownErrors:
goto handle_IgnoreChownErrors
case ffjtTarOptionsChownOpts:
goto handle_ChownOpts
@@ -1224,6 +1247,41 @@ handle_GIDMaps:
state = fflib.FFParse_after_value
goto mainparse
handle_IgnoreChownErrors:
/* handler: j.IgnoreChownErrors type=bool kind=bool quoted=false*/
{
if tok != fflib.FFTok_bool && tok != fflib.FFTok_null {
return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for bool", tok))
}
}
{
if tok == fflib.FFTok_null {
} else {
tmpb := fs.Output.Bytes()
if bytes.Compare([]byte{'t', 'r', 'u', 'e'}, tmpb) == 0 {
j.IgnoreChownErrors = true
} else if bytes.Compare([]byte{'f', 'a', 'l', 's', 'e'}, tmpb) == 0 {
j.IgnoreChownErrors = false
} else {
err = errors.New("unexpected bytes for true/false value")
return fs.WrapErr(err)
}
}
}
state = fflib.FFParse_after_value
goto mainparse
handle_ChownOpts:
/* handler: j.ChownOpts type=idtools.IDPair kind=struct quoted=false*/

View File

@@ -1,16 +0,0 @@
// +build !cgo
package archive
import (
"fmt"
"io"
)
func zstdReader(buf io.Reader) (io.ReadCloser, error) {
return nil, fmt.Errorf("zstd not supported on this platform")
}
func zstdWriter(dest io.Writer) (io.WriteCloser, error) {
return nil, fmt.Errorf("zstd not supported on this platform")
}

View File

@@ -0,0 +1,41 @@
package archive
import (
"io"
"github.com/klauspost/compress/zstd"
)
type wrapperZstdDecoder struct {
decoder *zstd.Decoder
}
func (w *wrapperZstdDecoder) Close() error {
w.decoder.Close()
return nil
}
func (w *wrapperZstdDecoder) DecodeAll(input, dst []byte) ([]byte, error) {
return w.decoder.DecodeAll(input, dst)
}
func (w *wrapperZstdDecoder) Read(p []byte) (int, error) {
return w.decoder.Read(p)
}
func (w *wrapperZstdDecoder) Reset(r io.Reader) error {
return w.decoder.Reset(r)
}
func (w *wrapperZstdDecoder) WriteTo(wr io.Writer) (int64, error) {
return w.decoder.WriteTo(wr)
}
func zstdReader(buf io.Reader) (io.ReadCloser, error) {
decoder, err := zstd.NewReader(buf)
return &wrapperZstdDecoder{decoder: decoder}, err
}
func zstdWriter(dest io.Writer) (io.WriteCloser, error) {
return zstd.NewWriter(dest)
}

View File

@@ -105,7 +105,7 @@ func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64,
}
defer os.RemoveAll(aufsTempdir)
}
if err := createTarFile(filepath.Join(aufsTempdir, basename), dest, hdr, tr, true, nil, options.InUserNS); err != nil {
if err := createTarFile(filepath.Join(aufsTempdir, basename), dest, hdr, tr, true, nil, options.InUserNS, options.IgnoreChownErrors); err != nil {
return 0, err
}
}
@@ -196,7 +196,7 @@ func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64,
return 0, err
}
if err := createTarFile(path, dest, srcHdr, srcData, true, nil, options.InUserNS); err != nil {
if err := createTarFile(path, dest, srcHdr, srcData, true, nil, options.InUserNS, options.IgnoreChownErrors); err != nil {
return 0, err
}