Vendor Buildah 1.10.1

As the title says, vendor Buildah v1.10.1

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
This commit is contained in:
TomSweeneyRedHat
2019-08-08 16:05:35 -04:00
parent 09cedd152d
commit 711474d92e
74 changed files with 3343 additions and 301 deletions

View File

@@ -10,6 +10,7 @@ import (
"strings"
"syscall"
"github.com/containers/storage/pkg/system"
"github.com/pkg/errors"
)
@@ -296,9 +297,19 @@ func checkChownErr(err error, name string, uid, gid int) error {
}
func SafeChown(name string, uid, gid int) error {
if stat, statErr := system.Stat(name); statErr == nil {
if stat.UID() == uint32(uid) && stat.GID() == uint32(gid) {
return nil
}
}
return checkChownErr(os.Chown(name, uid, gid), name, uid, gid)
}
func SafeLchown(name string, uid, gid int) error {
if stat, statErr := system.Lstat(name); statErr == nil {
if stat.UID() == uint32(uid) && stat.GID() == uint32(gid) {
return nil
}
}
return checkChownErr(os.Lchown(name, uid, gid), name, uid, gid)
}

View File

@@ -1,4 +1,4 @@
// +build linux
// +build linux,cgo
package loopback

View File

@@ -1,4 +1,4 @@
// +build linux
// +build linux,cgo
package loopback

View File

@@ -1,4 +1,4 @@
// +build linux
// +build linux,cgo
package loopback

View File

@@ -1,4 +1,4 @@
// +build linux
// +build linux,cgo
package loopback

View File

@@ -0,0 +1 @@
package loopback

View File

@@ -1,4 +1,4 @@
// +build !ostree
// +build !ostree !cgo
package ostree

View File

@@ -1,4 +1,4 @@
// +build ostree
// +build ostree,cgo
package ostree

View File

@@ -1,47 +1,69 @@
package tarlog
import (
"archive/tar"
"io"
"os"
"sync"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vbatts/tar-split/archive/tar"
)
type tarLogger struct {
writer *os.File
wg sync.WaitGroup
writer *io.PipeWriter
closeMutex *sync.Mutex
stateMutex *sync.Mutex
closed bool
}
// NewLogger returns a writer that, when a tar archive is written to it, calls
// `logger` for each file header it encounters in the archive.
func NewLogger(logger func(*tar.Header)) (io.WriteCloser, error) {
reader, writer, err := os.Pipe()
if err != nil {
return nil, errors.Wrapf(err, "error creating pipe for tar logger")
reader, writer := io.Pipe()
t := &tarLogger{
writer: writer,
closeMutex: new(sync.Mutex),
stateMutex: new(sync.Mutex),
closed: false,
}
t := &tarLogger{writer: writer}
tr := tar.NewReader(reader)
t.wg.Add(1)
tr.RawAccounting = true
t.closeMutex.Lock()
go func() {
hdr, err := tr.Next()
for err == nil {
logger(hdr)
hdr, err = tr.Next()
}
reader.Close()
t.wg.Done()
// Make sure to avoid writes after the reader has been closed.
t.stateMutex.Lock()
t.closed = true
if err := reader.Close(); err != nil {
logrus.Errorf("error closing tarlogger reader: %v", err)
}
t.stateMutex.Unlock()
// Unblock the Close().
t.closeMutex.Unlock()
}()
return t, nil
}
func (t *tarLogger) Write(b []byte) (int, error) {
t.stateMutex.Lock()
if t.closed {
// We cannot use os.Pipe() as this alters the tar's digest. Using
// io.Pipe() requires this workaround as it does not allow for writes
// after close.
t.stateMutex.Unlock()
return len(b), nil
}
t.stateMutex.Unlock()
return t.writer.Write(b)
}
func (t *tarLogger) Close() error {
err := t.writer.Close()
t.wg.Wait()
// Wait for the reader to finish.
t.closeMutex.Lock()
return err
}