Update log lines to use containerd log package
Removed unused requires root test function and updated tar requires function to use lookup method. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
f0a43e72cd
commit
6443891a7d
5 changed files with 20 additions and 44 deletions
|
@ -14,8 +14,8 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/containerd/fs"
|
"github.com/docker/containerd/fs"
|
||||||
|
"github.com/docker/containerd/log"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ var (
|
||||||
breakoutError = errors.New("file name outside of root")
|
breakoutError = errors.New("file name outside of root")
|
||||||
)
|
)
|
||||||
|
|
||||||
// TarFromChanges returns a tar stream of the computed filesystem
|
// Diff returns a tar stream of the computed filesystem
|
||||||
// difference between the provided directories.
|
// difference between the provided directories.
|
||||||
//
|
//
|
||||||
// Produces a tar using OCI style file markers for deletions. Deleted
|
// Produces a tar using OCI style file markers for deletions. Deleted
|
||||||
// files will be prepended with the prefix ".wh.". This style is
|
// files will be prepended with the prefix ".wh.". This style is
|
||||||
// based off AUFS whiteouts.
|
// based off AUFS whiteouts.
|
||||||
// See https://github.com/opencontainers/image-spec/blob/master/layer.md
|
// See https://github.com/opencontainers/image-spec/blob/master/layer.md
|
||||||
func DiffTarStream(ctx context.Context, a, b string) io.ReadCloser {
|
func Diff(ctx context.Context, a, b string) io.ReadCloser {
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -48,7 +48,7 @@ func DiffTarStream(ctx context.Context, a, b string) io.ReadCloser {
|
||||||
err = cw.Close()
|
err = cw.Close()
|
||||||
}
|
}
|
||||||
if err = w.CloseWithError(err); err != nil {
|
if err = w.CloseWithError(err); err != nil {
|
||||||
logrus.Errorf("Error closing tar pipe: %v", err)
|
log.G(ctx).WithError(err).Debugf("closing tar pipe failed")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -76,9 +76,9 @@ const (
|
||||||
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
|
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApplyDiffTar applies a tar stream of an OCI style diff tar.
|
// Apply applies a tar stream of an OCI style diff tar.
|
||||||
// See https://github.com/opencontainers/image-spec/blob/master/layer.md#applying-changesets
|
// See https://github.com/opencontainers/image-spec/blob/master/layer.md#applying-changesets
|
||||||
func ApplyDiffTar(ctx context.Context, root string, r io.Reader) (int64, error) {
|
func Apply(ctx context.Context, root string, r io.Reader) (int64, error) {
|
||||||
root = filepath.Clean(root)
|
root = filepath.Clean(root)
|
||||||
fn := prepareApply()
|
fn := prepareApply()
|
||||||
defer fn()
|
defer fn()
|
||||||
|
@ -114,6 +114,7 @@ func ApplyDiffTar(ctx context.Context, root string, r io.Reader) (int64, error)
|
||||||
hdr.Name = filepath.Clean(hdr.Name)
|
hdr.Name = filepath.Clean(hdr.Name)
|
||||||
|
|
||||||
if skipFile(hdr) {
|
if skipFile(hdr) {
|
||||||
|
log.G(ctx).Warnf("file %q ignored: archive may not be supported on system", hdr.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ func ApplyDiffTar(ctx context.Context, root string, r io.Reader) (int64, error)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(aufsTempdir)
|
defer os.RemoveAll(aufsTempdir)
|
||||||
}
|
}
|
||||||
if err := createTarFile(filepath.Join(aufsTempdir, basename), root, hdr, tr); err != nil {
|
if err := createTarFile(ctx, filepath.Join(aufsTempdir, basename), root, hdr, tr); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,7 +237,7 @@ func ApplyDiffTar(ctx context.Context, root string, r io.Reader) (int64, error)
|
||||||
srcData = tmpFile
|
srcData = tmpFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createTarFile(path, root, srcHdr, srcData); err != nil {
|
if err := createTarFile(ctx, path, root, srcHdr, srcData); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +385,7 @@ func (cw *changeWriter) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) error {
|
func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header, reader io.Reader) 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)
|
||||||
|
@ -451,7 +452,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e
|
||||||
}
|
}
|
||||||
|
|
||||||
case tar.TypeXGlobalHeader:
|
case tar.TypeXGlobalHeader:
|
||||||
logrus.Debug("PAX Global Extended Headers found and ignored")
|
log.G(ctx).Debug("PAX Global Extended Headers found and ignored")
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -465,24 +466,16 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var warnErrors []string
|
|
||||||
for key, value := range hdr.Xattrs {
|
for key, value := range hdr.Xattrs {
|
||||||
if err := setxattr(path, key, value); err != nil {
|
if err := setxattr(path, key, value); err != nil {
|
||||||
if errors.Cause(err) == syscall.ENOTSUP {
|
if errors.Cause(err) == syscall.ENOTSUP {
|
||||||
// Collect errors only for filesystem warning
|
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
|
||||||
warnErrors = append(warnErrors, err.Error())
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(warnErrors) > 0 {
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"errors": warnErrors,
|
|
||||||
}).Warn("ignored xattrs in archive: underlying filesystem doesn't support them")
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is no LChmod, so ignore mode for symlink. Also, this
|
// There is no LChmod, so ignore mode for symlink. Also, this
|
||||||
// must happen after chown, as that can modify the file mode
|
// must happen after chown, as that can modify the file mode
|
||||||
if err := handleLChmod(hdr, path, hdrInfo); err != nil {
|
if err := handleLChmod(hdr, path, hdrInfo); err != nil {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const tarCmd = "/usr/bin/tar"
|
const tarCmd = "tar"
|
||||||
|
|
||||||
// baseApplier creates a basic filesystem layout
|
// baseApplier creates a basic filesystem layout
|
||||||
// with multiple types of files for basic tests.
|
// with multiple types of files for basic tests.
|
||||||
|
@ -113,7 +112,7 @@ func testApply(a fstest.Applier) error {
|
||||||
return errors.Wrap(err, "failed to start command")
|
return errors.Wrap(err, "failed to start command")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := ApplyDiffTar(context.Background(), dest, arch); err != nil {
|
if _, err := Apply(context.Background(), dest, arch); err != nil {
|
||||||
return errors.Wrap(err, "failed to apply tar stream")
|
return errors.Wrap(err, "failed to apply tar stream")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +135,7 @@ func testBaseDiff(a fstest.Applier) error {
|
||||||
return errors.Wrap(err, "failed to apply filesystem changes")
|
return errors.Wrap(err, "failed to apply filesystem changes")
|
||||||
}
|
}
|
||||||
|
|
||||||
arch := DiffTarStream(context.Background(), "", td)
|
arch := Diff(context.Background(), "", td)
|
||||||
|
|
||||||
cmd := exec.Command(tarCmd, "x", "-C", dest)
|
cmd := exec.Command(tarCmd, "x", "-C", dest)
|
||||||
cmd.Stdin = arch
|
cmd.Stdin = arch
|
||||||
|
@ -184,7 +183,7 @@ func diffApply(ctx context.Context, a fstest.Applier, base, dest string) error {
|
||||||
return errors.Wrap(err, "failed to apply changes to base")
|
return errors.Wrap(err, "failed to apply changes to base")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := ApplyDiffTar(ctx, dest, DiffTarStream(ctx, baseCopy, base)); err != nil {
|
if _, err := Apply(ctx, dest, Diff(ctx, baseCopy, base)); err != nil {
|
||||||
return errors.Wrap(err, "failed to apply tar stream")
|
return errors.Wrap(err, "failed to apply tar stream")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,21 +203,7 @@ func readDirNames(p string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func requireTar(t *testing.T) {
|
func requireTar(t *testing.T) {
|
||||||
if _, err := os.Stat(tarCmd); err != nil {
|
if _, err := exec.LookPath(tarCmd); err != nil {
|
||||||
if os.IsNotExist(err) {
|
t.Skipf("%s not found, skipping", tarCmd)
|
||||||
t.Skipf("%s not found, skipping", tarCmd)
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Unable to stat %s: %v", tarCmd, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func requireRoot(t *testing.T) {
|
|
||||||
u, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unable to get current user: %v", err)
|
|
||||||
}
|
|
||||||
if u.Uid != "0" {
|
|
||||||
t.Skipf("test requires root, skipping")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,7 +77,6 @@ func skipFile(hdr *tar.Header) bool {
|
||||||
// to cater for the situation where someone does manage to upload a Linux
|
// to cater for the situation where someone does manage to upload a Linux
|
||||||
// image but have it tagged as Windows inadvertently.
|
// image but have it tagged as Windows inadvertently.
|
||||||
if strings.Contains(hdr.Name, ":") {
|
if strings.Contains(hdr.Name, ":") {
|
||||||
logrus.Warnf("Windows: Ignoring %s (is this a Linux image?)", hdr.Name)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
cmd/dist/apply.go
vendored
2
cmd/dist/apply.go
vendored
|
@ -28,7 +28,7 @@ var applyCommand = cli.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := archive.ApplyDiffTar(ctx, dir, rd); err != nil {
|
if _, err := archive.Apply(ctx, dir, rd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ func ApplyLayer(snapshots snapshot.Snapshotter, mounter Mounter, rd io.Reader, p
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := archive.ApplyDiffTar(context.Background(), key, rd); err != nil {
|
if _, err := archive.Apply(context.Background(), key, rd); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue