Update files based on go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
70b353dff2
commit
f43b7acfd2
@ -522,9 +522,5 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
|
||||
return err
|
||||
}
|
||||
|
||||
if err := chtimes(path, boundTime(latestTime(hdr.AccessTime, hdr.ModTime)), boundTime(hdr.ModTime)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return chtimes(path, boundTime(latestTime(hdr.AccessTime, hdr.ModTime)), boundTime(hdr.ModTime))
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ func TestSymlinks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBreakouts(t *testing.T) {
|
||||
tc := TarContext{}.WithUidGid(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
|
||||
tc := TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
|
||||
expected := "unbroken"
|
||||
unbrokenCheck := func(root string) error {
|
||||
b, err := ioutil.ReadFile(filepath.Join(root, "etc", "unbroken"))
|
||||
@ -480,7 +480,7 @@ func TestDiffApply(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApplyTar(t *testing.T) {
|
||||
tc := TarContext{}.WithUidGid(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
|
||||
tc := TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
|
||||
directoriesExist := func(dirs ...string) func(string) error {
|
||||
return func(root string) error {
|
||||
for _, d := range dirs {
|
||||
@ -767,8 +767,8 @@ func TarFromWriterTo(wt WriterToTar) io.ReadCloser {
|
||||
|
||||
// TarContext is used to create tar records
|
||||
type TarContext struct {
|
||||
Uid int
|
||||
Gid int
|
||||
UID int
|
||||
GID int
|
||||
|
||||
// ModTime sets the modtimes for all files, if nil the current time
|
||||
// is used for each file when it was written
|
||||
@ -784,8 +784,8 @@ func (tc TarContext) newHeader(mode os.FileMode, name, link string, size int64)
|
||||
size: size,
|
||||
modt: tc.ModTime,
|
||||
hdr: &tar.Header{
|
||||
Uid: tc.Uid,
|
||||
Gid: tc.Gid,
|
||||
Uid: tc.UID,
|
||||
Gid: tc.GID,
|
||||
Xattrs: tc.Xattrs,
|
||||
},
|
||||
}
|
||||
@ -837,10 +837,10 @@ func (ti tarInfo) Sys() interface{} {
|
||||
return ti.hdr
|
||||
}
|
||||
|
||||
func (tc TarContext) WithUidGid(uid, gid int) TarContext {
|
||||
func (tc TarContext) WithUIDGID(uid, gid int) TarContext {
|
||||
ntc := tc
|
||||
ntc.Uid = uid
|
||||
ntc.Gid = gid
|
||||
ntc.UID = uid
|
||||
ntc.GID = gid
|
||||
return ntc
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ type unixSocketCredentials struct {
|
||||
serverName string
|
||||
}
|
||||
|
||||
// NewUnixSocketCredentials returns TransportCredentials for a local unix socket
|
||||
func NewUnixSocketCredentials(uid, gid int) credentials.TransportCredentials {
|
||||
return &unixSocketCredentials{uid, gid, "locahost"}
|
||||
}
|
||||
|
@ -44,12 +44,7 @@ var namespacesCreateCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := namespaces.Create(ctx, namespace, labels); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return namespaces.Create(ctx, namespace, labels)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,6 @@ var taskPsCommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return w.Flush()
|
||||
},
|
||||
}
|
||||
|
@ -62,11 +62,13 @@ type Container struct {
|
||||
Extensions map[string]types.Any
|
||||
}
|
||||
|
||||
// RuntimeInfo holds runtime specific information
|
||||
type RuntimeInfo struct {
|
||||
Name string
|
||||
Options *types.Any
|
||||
}
|
||||
|
||||
// Store interacts with the underlying container storage
|
||||
type Store interface {
|
||||
Get(ctx context.Context, id string) (Container, error)
|
||||
|
||||
|
@ -8,20 +8,25 @@ import (
|
||||
"github.com/opencontainers/go-digest"
|
||||
)
|
||||
|
||||
// ReaderAt extends the standard io.ReaderAt interface with reporting of Size and io.Closer
|
||||
type ReaderAt interface {
|
||||
io.ReaderAt
|
||||
io.Closer
|
||||
Size() int64
|
||||
}
|
||||
|
||||
// Provider provides a reader interface for specific content
|
||||
type Provider interface {
|
||||
ReaderAt(ctx context.Context, dgst digest.Digest) (ReaderAt, error)
|
||||
}
|
||||
|
||||
// Ingester writes content
|
||||
type Ingester interface {
|
||||
Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (Writer, error)
|
||||
}
|
||||
|
||||
// Info holds content specific information
|
||||
//
|
||||
// TODO(stevvooe): Consider a very different name for this struct. Info is way
|
||||
// to general. It also reads very weird in certain context, like pluralization.
|
||||
type Info struct {
|
||||
@ -32,6 +37,7 @@ type Info struct {
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
// Status of a content operation
|
||||
type Status struct {
|
||||
Ref string
|
||||
Offset int64
|
||||
@ -81,6 +87,7 @@ type IngestManager interface {
|
||||
Abort(ctx context.Context, ref string) error
|
||||
}
|
||||
|
||||
// Writer handles the write of content into a content store
|
||||
type Writer interface {
|
||||
// Close is expected to be called after Commit() when commission is needed.
|
||||
io.WriteCloser
|
||||
@ -111,6 +118,7 @@ type Store interface {
|
||||
// Opt is used to alter the mutable properties of content
|
||||
type Opt func(*Info) error
|
||||
|
||||
// WithLabels allows labels to be set on content
|
||||
func WithLabels(labels map[string]string) Opt {
|
||||
return func(info *Info) error {
|
||||
info.Labels = labels
|
||||
|
@ -19,6 +19,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// NewReader returns a io.Reader from a ReaderAt
|
||||
func NewReader(ra ReaderAt) io.Reader {
|
||||
rd := io.NewSectionReader(ra, 0, ra.Size())
|
||||
return rd
|
||||
|
@ -36,6 +36,7 @@ type store struct {
|
||||
root string
|
||||
}
|
||||
|
||||
// NewServer returns a local content store
|
||||
func NewStore(root string) (content.Store, error) {
|
||||
if err := os.MkdirAll(filepath.Join(root, "ingest"), 0777); err != nil && !os.IsExist(err) {
|
||||
return nil, err
|
||||
@ -97,8 +98,8 @@ func (s *store) ReaderAt(ctx context.Context, dgst digest.Digest) (content.Reade
|
||||
//
|
||||
// While this is safe to do concurrently, safe exist-removal logic must hold
|
||||
// some global lock on the store.
|
||||
func (cs *store) Delete(ctx context.Context, dgst digest.Digest) error {
|
||||
if err := os.RemoveAll(cs.blobPath(dgst)); err != nil {
|
||||
func (s *store) Delete(ctx context.Context, dgst digest.Digest) error {
|
||||
if err := os.RemoveAll(s.blobPath(dgst)); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
@ -109,14 +110,14 @@ func (cs *store) Delete(ctx context.Context, dgst digest.Digest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *store) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
|
||||
func (s *store) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
|
||||
// TODO: Support persisting and updating mutable content data
|
||||
return content.Info{}, errors.Wrapf(errdefs.ErrFailedPrecondition, "update not supported on immutable content store")
|
||||
}
|
||||
|
||||
func (cs *store) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
|
||||
func (s *store) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
|
||||
// TODO: Support filters
|
||||
root := filepath.Join(cs.root, "blobs")
|
||||
root := filepath.Join(s.root, "blobs")
|
||||
var alg digest.Algorithm
|
||||
return filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
@ -153,7 +154,7 @@ func (cs *store) Walk(ctx context.Context, fn content.WalkFunc, filters ...strin
|
||||
// store or extra paths not expected previously.
|
||||
}
|
||||
|
||||
return fn(cs.info(dgst, fi))
|
||||
return fn(s.info(dgst, fi))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ var (
|
||||
ErrNotImplemented = errors.New("not implemented") // represents not supported and unimplemented
|
||||
)
|
||||
|
||||
// IsInvalidArgument returns true if the error is due to an invalid argument
|
||||
func IsInvalidArgument(err error) bool {
|
||||
return errors.Cause(err) == ErrInvalidArgument
|
||||
}
|
||||
@ -45,15 +46,17 @@ func IsAlreadyExists(err error) bool {
|
||||
}
|
||||
|
||||
// IsFailedPrecondition returns true if an operation could not proceed to the
|
||||
// lack of a particular condition.
|
||||
// lack of a particular condition
|
||||
func IsFailedPrecondition(err error) bool {
|
||||
return errors.Cause(err) == ErrFailedPrecondition
|
||||
}
|
||||
|
||||
// IsUnavailable returns true if the error is due to a resource being unavailable
|
||||
func IsUnavailable(err error) bool {
|
||||
return errors.Cause(err) == ErrUnavailable
|
||||
}
|
||||
|
||||
// IsNotImplemented returns true if the error is due to not being implemented
|
||||
func IsNotImplemented(err error) bool {
|
||||
return errors.Cause(err) == ErrNotImplemented
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ func ToGRPCf(err error, format string, args ...interface{}) error {
|
||||
return ToGRPC(errors.Wrapf(err, format, args...))
|
||||
}
|
||||
|
||||
// FromGRPC returns the underlying error from a grpc service based on the grpc error code
|
||||
func FromGRPC(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
events "github.com/containerd/containerd/api/services/events/v1"
|
||||
)
|
||||
|
||||
// Event is a generic interface for any type of event
|
||||
type Event interface{}
|
||||
|
||||
// Publisher posts the event.
|
||||
@ -13,6 +14,7 @@ type Publisher interface {
|
||||
Publish(ctx context.Context, topic string, event Event) error
|
||||
}
|
||||
|
||||
// Forwarder forwards an event to the underlying event bus
|
||||
type Forwarder interface {
|
||||
Forward(ctx context.Context, envelope *events.Envelope) error
|
||||
}
|
||||
@ -23,6 +25,7 @@ func (fn publisherFunc) Publish(ctx context.Context, topic string, event Event)
|
||||
return fn(ctx, topic, event)
|
||||
}
|
||||
|
||||
// Subscriber allows callers to subscribe to events
|
||||
type Subscriber interface {
|
||||
Subscribe(ctx context.Context, filters ...string) (ch <-chan *events.Envelope, errs <-chan error)
|
||||
}
|
||||
|
@ -18,10 +18,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Exchange broadcasts events
|
||||
type Exchange struct {
|
||||
broadcaster *goevents.Broadcaster
|
||||
}
|
||||
|
||||
// NewExchange returns a new event Exchange
|
||||
func NewExchange() *Exchange {
|
||||
return &Exchange{
|
||||
broadcaster: goevents.NewBroadcaster(),
|
||||
|
@ -8,8 +8,10 @@ type Adaptor interface {
|
||||
Field(fieldpath []string) (value string, present bool)
|
||||
}
|
||||
|
||||
// AdapterFunc allows implementation specific matching of fieldpaths
|
||||
type AdapterFunc func(fieldpath []string) (string, bool)
|
||||
|
||||
// Field returns the field name and true if it exists
|
||||
func (fn AdapterFunc) Field(fieldpath []string) (string, bool) {
|
||||
return fn(fieldpath)
|
||||
}
|
||||
|
@ -58,22 +58,28 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
)
|
||||
|
||||
// Filter matches specific resources based the provided filter
|
||||
type Filter interface {
|
||||
Match(adaptor Adaptor) bool
|
||||
}
|
||||
|
||||
// FilterFunc is a function that handles matching with an adaptor
|
||||
type FilterFunc func(Adaptor) bool
|
||||
|
||||
// Match matches the FilterFunc returning true if the object matches the filter
|
||||
func (fn FilterFunc) Match(adaptor Adaptor) bool {
|
||||
return fn(adaptor)
|
||||
}
|
||||
|
||||
// Always is a filter that always returns true for any type of object
|
||||
var Always FilterFunc = func(adaptor Adaptor) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Any allows multiple filters to be matched aginst the object
|
||||
type Any []Filter
|
||||
|
||||
// Match returns true if any of the provided filters are true
|
||||
func (m Any) Match(adaptor Adaptor) bool {
|
||||
for _, m := range m {
|
||||
if m.Match(adaptor) {
|
||||
@ -84,8 +90,10 @@ func (m Any) Match(adaptor Adaptor) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// All allows multiple filters to be matched aginst the object
|
||||
type All []Filter
|
||||
|
||||
// Match only returns true if all filters match the object
|
||||
func (m All) Match(adaptor Adaptor) bool {
|
||||
for _, m := range m {
|
||||
if !m.Match(adaptor) {
|
||||
|
@ -243,10 +243,9 @@ func TestFilters(t *testing.T) {
|
||||
}
|
||||
|
||||
return
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if filter == nil {
|
||||
|
@ -67,9 +67,8 @@ func (s *scanner) next() rune {
|
||||
if r == utf8.RuneError {
|
||||
if w > 0 {
|
||||
return tokenIllegal
|
||||
} else {
|
||||
return tokenEOF
|
||||
}
|
||||
return tokenEOF
|
||||
}
|
||||
|
||||
if r == 0 {
|
||||
|
1
fs/du.go
1
fs/du.go
@ -1,5 +1,6 @@
|
||||
package fs
|
||||
|
||||
// Usage of disk information
|
||||
type Usage struct {
|
||||
Inodes int64
|
||||
Size int64
|
||||
|
@ -26,12 +26,7 @@ func CreateFile(name string, content []byte, perm os.FileMode) Applier {
|
||||
if err := ioutil.WriteFile(fullPath, content, perm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chmod(fullPath, perm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return os.Chmod(fullPath, perm)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ package fstest
|
||||
|
||||
import "github.com/containerd/continuity/sysx"
|
||||
|
||||
// SetXAttr sets the xatter for the file
|
||||
func SetXAttr(name, key, value string) Applier {
|
||||
return applyFn(func(root string) error {
|
||||
return sysx.LSetxattr(name, key, []byte(value), 0)
|
||||
|
@ -7,11 +7,13 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestApplier applies the test context
|
||||
type TestApplier interface {
|
||||
TestContext(context.Context) (context.Context, func(), error)
|
||||
Apply(context.Context, Applier) (string, func(), error)
|
||||
}
|
||||
|
||||
// FSSuite runs the path test suite
|
||||
func FSSuite(t *testing.T, a TestApplier) {
|
||||
t.Run("Basic", makeTest(t, a, basicTest))
|
||||
t.Run("Deletion", makeTest(t, a, deletionTest))
|
||||
|
@ -2,7 +2,7 @@ package fs
|
||||
|
||||
import "os"
|
||||
|
||||
// GetLinkID returns an identifier representing the node a hardlink is pointing
|
||||
// GetLinkInfo returns an identifier representing the node a hardlink is pointing
|
||||
// to. If the file is not hard linked then 0 will be returned.
|
||||
func GetLinkInfo(fi os.FileInfo) (uint64, bool) {
|
||||
return getLinkInfo(fi)
|
||||
|
Loading…
Reference in New Issue
Block a user