Skip to content

Commit

Permalink
Merge pull request containerd#1577 from crosbymichael/lint-1
Browse files Browse the repository at this point in the history
Update files based on go lint
  • Loading branch information
crosbymichael authored Oct 2, 2017
2 parents 2416559 + f43b7ac commit 33e974c
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 44 deletions.
6 changes: 1 addition & 5 deletions archive/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
18 changes: 9 additions & 9 deletions archive/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
}
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions cmd/containerd-shim/shim_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/ctr/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
5 changes: 1 addition & 4 deletions cmd/ctr/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ var taskPsCommand = cli.Command{
return err
}
}
if err := w.Flush(); err != nil {
return err
}
return nil
return w.Flush()
},
}
2 changes: 2 additions & 0 deletions containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,6 +37,7 @@ type Info struct {
Labels map[string]string
}

// Status of a content operation
type Status struct {
Ref string
Offset int64
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions content/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions content/local/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
})
}

Expand Down
5 changes: 4 additions & 1 deletion errdefs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
1 change: 1 addition & 0 deletions errdefs/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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.
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
}
Expand All @@ -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)
}
2 changes: 2 additions & 0 deletions events/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions filters/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions filters/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions filters/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions fs/du.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fs

// Usage of disk information
type Usage struct {
Inodes int64
Size int64
Expand Down
7 changes: 1 addition & 6 deletions fs/fstest/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
1 change: 1 addition & 0 deletions fs/fstest/file_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 33e974c

Please sign in to comment.