Fix go lint errors
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
8509569329
commit
b6e0c4f321
@ -137,7 +137,7 @@ func TestWalkBlobs(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blobs = populateBlobStore(t, ctx, cs, nblobs, maxsize)
|
blobs = populateBlobStore(ctx, t, cs, nblobs, maxsize)
|
||||||
expected = map[digest.Digest]struct{}{}
|
expected = map[digest.Digest]struct{}{}
|
||||||
found = map[digest.Digest]struct{}{}
|
found = map[digest.Digest]struct{}{}
|
||||||
)
|
)
|
||||||
@ -188,7 +188,7 @@ func BenchmarkIngests(b *testing.B) {
|
|||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
|
|
||||||
for dgst, p := range blobs {
|
for dgst, p := range blobs {
|
||||||
checkWrite(b, ctx, cs, dgst, p)
|
checkWrite(ctx, b, cs, dgst, p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -215,11 +215,11 @@ func generateBlobs(t checker, nblobs, maxsize int64) map[digest.Digest][]byte {
|
|||||||
return blobs
|
return blobs
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateBlobStore(t checker, ctx context.Context, cs content.Store, nblobs, maxsize int64) map[digest.Digest][]byte {
|
func populateBlobStore(ctx context.Context, t checker, cs content.Store, nblobs, maxsize int64) map[digest.Digest][]byte {
|
||||||
blobs := generateBlobs(t, nblobs, maxsize)
|
blobs := generateBlobs(t, nblobs, maxsize)
|
||||||
|
|
||||||
for dgst, p := range blobs {
|
for dgst, p := range blobs {
|
||||||
checkWrite(t, ctx, cs, dgst, p)
|
checkWrite(ctx, t, cs, dgst, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return blobs
|
return blobs
|
||||||
@ -282,7 +282,7 @@ func checkBlobPath(t *testing.T, cs content.Store, dgst digest.Digest) string {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkWrite(t checker, ctx context.Context, cs content.Store, dgst digest.Digest, p []byte) digest.Digest {
|
func checkWrite(ctx context.Context, t checker, cs content.Store, dgst digest.Digest, p []byte) digest.Digest {
|
||||||
if err := content.WriteBlob(ctx, cs, dgst.String(), bytes.NewReader(p), int64(len(p)), dgst); err != nil {
|
if err := content.WriteBlob(ctx, cs, dgst.String(), bytes.NewReader(p), int64(len(p)), dgst); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func TestSimpleDiff(t *testing.T) {
|
|||||||
fstest.CreateFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644),
|
fstest.CreateFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644),
|
||||||
fstest.Remove("/etc/unexpected"),
|
fstest.Remove("/etc/unexpected"),
|
||||||
)
|
)
|
||||||
diff := []testChange{
|
diff := []TestChange{
|
||||||
Modify("/etc/hosts"),
|
Modify("/etc/hosts"),
|
||||||
Modify("/etc/profile"),
|
Modify("/etc/profile"),
|
||||||
Delete("/etc/unexpected"),
|
Delete("/etc/unexpected"),
|
||||||
@ -60,7 +60,7 @@ func TestDirectoryReplace(t *testing.T) {
|
|||||||
fstest.RemoveAll("/dir1/f2"),
|
fstest.RemoveAll("/dir1/f2"),
|
||||||
fstest.CreateFile("/dir1/f2", []byte("Now file"), 0666),
|
fstest.CreateFile("/dir1/f2", []byte("Now file"), 0666),
|
||||||
)
|
)
|
||||||
diff := []testChange{
|
diff := []TestChange{
|
||||||
Add("/dir1/f11"),
|
Add("/dir1/f11"),
|
||||||
Modify("/dir1/f2"),
|
Modify("/dir1/f2"),
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func TestRemoveDirectoryTree(t *testing.T) {
|
|||||||
l2 := fstest.Apply(
|
l2 := fstest.Apply(
|
||||||
fstest.RemoveAll("/dir1"),
|
fstest.RemoveAll("/dir1"),
|
||||||
)
|
)
|
||||||
diff := []testChange{
|
diff := []TestChange{
|
||||||
Delete("/dir1"),
|
Delete("/dir1"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func TestFileReplace(t *testing.T) {
|
|||||||
fstest.CreateDir("/dir1/dir2", 0755),
|
fstest.CreateDir("/dir1/dir2", 0755),
|
||||||
fstest.CreateFile("/dir1/dir2/f1", []byte("also a file"), 0644),
|
fstest.CreateFile("/dir1/dir2/f1", []byte("also a file"), 0644),
|
||||||
)
|
)
|
||||||
diff := []testChange{
|
diff := []TestChange{
|
||||||
Modify("/dir1"),
|
Modify("/dir1"),
|
||||||
Add("/dir1/dir2"),
|
Add("/dir1/dir2"),
|
||||||
Add("/dir1/dir2/f1"),
|
Add("/dir1/dir2/f1"),
|
||||||
@ -136,7 +136,7 @@ func TestUpdateWithSameTime(t *testing.T) {
|
|||||||
fstest.CreateFile("/file-truncated-time-2", []byte("2"), 0644),
|
fstest.CreateFile("/file-truncated-time-2", []byte("2"), 0644),
|
||||||
fstest.Chtime("/file-truncated-time-2", tt),
|
fstest.Chtime("/file-truncated-time-2", tt),
|
||||||
)
|
)
|
||||||
diff := []testChange{
|
diff := []TestChange{
|
||||||
// "/file-same-time" excluded because matching non-zero nanosecond values
|
// "/file-same-time" excluded because matching non-zero nanosecond values
|
||||||
Modify("/file-modified-time"),
|
Modify("/file-modified-time"),
|
||||||
Modify("/file-truncated-time-1"),
|
Modify("/file-truncated-time-1"),
|
||||||
@ -148,7 +148,7 @@ func TestUpdateWithSameTime(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDiffWithBase(base, diff fstest.Applier, expected []testChange) error {
|
func testDiffWithBase(base, diff fstest.Applier, expected []TestChange) error {
|
||||||
t1, err := ioutil.TempDir("", "diff-with-base-lower-")
|
t1, err := ioutil.TempDir("", "diff-with-base-lower-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create temp dir")
|
return errors.Wrap(err, "failed to create temp dir")
|
||||||
@ -188,7 +188,7 @@ func TestBaseDirectoryChanges(t *testing.T) {
|
|||||||
fstest.CreateDir("/root", 0700),
|
fstest.CreateDir("/root", 0700),
|
||||||
fstest.CreateFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644),
|
fstest.CreateFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644),
|
||||||
)
|
)
|
||||||
changes := []testChange{
|
changes := []TestChange{
|
||||||
Add("/etc"),
|
Add("/etc"),
|
||||||
Add("/etc/hosts"),
|
Add("/etc/hosts"),
|
||||||
Add("/etc/profile"),
|
Add("/etc/profile"),
|
||||||
@ -201,7 +201,7 @@ func TestBaseDirectoryChanges(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDiffWithoutBase(apply fstest.Applier, expected []testChange) error {
|
func testDiffWithoutBase(apply fstest.Applier, expected []TestChange) error {
|
||||||
tmp, err := ioutil.TempDir("", "diff-without-base-")
|
tmp, err := ioutil.TempDir("", "diff-without-base-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create temp dir")
|
return errors.Wrap(err, "failed to create temp dir")
|
||||||
@ -220,7 +220,7 @@ func testDiffWithoutBase(apply fstest.Applier, expected []testChange) error {
|
|||||||
return checkChanges(tmp, changes, expected)
|
return checkChanges(tmp, changes, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkChanges(root string, changes, expected []testChange) error {
|
func checkChanges(root string, changes, expected []TestChange) error {
|
||||||
if len(changes) != len(expected) {
|
if len(changes) != len(expected) {
|
||||||
return errors.Errorf("Unexpected number of changes:\n%s", diffString(changes, expected))
|
return errors.Errorf("Unexpected number of changes:\n%s", diffString(changes, expected))
|
||||||
}
|
}
|
||||||
@ -253,20 +253,20 @@ func checkChanges(root string, changes, expected []testChange) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type testChange struct {
|
type TestChange struct {
|
||||||
Kind ChangeKind
|
Kind ChangeKind
|
||||||
Path string
|
Path string
|
||||||
FileInfo os.FileInfo
|
FileInfo os.FileInfo
|
||||||
Source string
|
Source string
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectChanges(a, b string) ([]testChange, error) {
|
func collectChanges(a, b string) ([]TestChange, error) {
|
||||||
changes := []testChange{}
|
changes := []TestChange{}
|
||||||
err := Changes(context.Background(), a, b, func(k ChangeKind, p string, f os.FileInfo, err error) error {
|
err := Changes(context.Background(), a, b, func(k ChangeKind, p string, f os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
changes = append(changes, testChange{
|
changes = append(changes, TestChange{
|
||||||
Kind: k,
|
Kind: k,
|
||||||
Path: p,
|
Path: p,
|
||||||
FileInfo: f,
|
FileInfo: f,
|
||||||
@ -281,12 +281,12 @@ func collectChanges(a, b string) ([]testChange, error) {
|
|||||||
return changes, nil
|
return changes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func diffString(c1, c2 []testChange) string {
|
func diffString(c1, c2 []TestChange) string {
|
||||||
return fmt.Sprintf("got(%d):\n%s\nexpected(%d):\n%s", len(c1), changesString(c1), len(c2), changesString(c2))
|
return fmt.Sprintf("got(%d):\n%s\nexpected(%d):\n%s", len(c1), changesString(c1), len(c2), changesString(c2))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func changesString(c []testChange) string {
|
func changesString(c []TestChange) string {
|
||||||
strs := make([]string, len(c))
|
strs := make([]string, len(c))
|
||||||
for i := range c {
|
for i := range c {
|
||||||
strs[i] = fmt.Sprintf("\t%s\t%s", c[i].Kind, c[i].Path)
|
strs[i] = fmt.Sprintf("\t%s\t%s", c[i].Kind, c[i].Path)
|
||||||
@ -294,22 +294,22 @@ func changesString(c []testChange) string {
|
|||||||
return strings.Join(strs, "\n")
|
return strings.Join(strs, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Add(p string) testChange {
|
func Add(p string) TestChange {
|
||||||
return testChange{
|
return TestChange{
|
||||||
Kind: ChangeKindAdd,
|
Kind: ChangeKindAdd,
|
||||||
Path: p,
|
Path: p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(p string) testChange {
|
func Delete(p string) TestChange {
|
||||||
return testChange{
|
return TestChange{
|
||||||
Kind: ChangeKindDelete,
|
Kind: ChangeKindDelete,
|
||||||
Path: p,
|
Path: p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Modify(p string) testChange {
|
func Modify(p string) TestChange {
|
||||||
return testChange{
|
return TestChange{
|
||||||
Kind: ChangeKindModify,
|
Kind: ChangeKindModify,
|
||||||
Path: p,
|
Path: p,
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type rootCheck struct {
|
type RootCheck struct {
|
||||||
unresolved string
|
unresolved string
|
||||||
expected string
|
expected string
|
||||||
scope func(string) string
|
scope func(string) string
|
||||||
@ -23,7 +23,7 @@ func TestRootPath(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
apply fstest.Applier
|
apply fstest.Applier
|
||||||
checks []rootCheck
|
checks []RootCheck
|
||||||
scope func(string) (string, error)
|
scope func(string) (string, error)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -201,7 +201,7 @@ func testRootPathSymlinkEmpty(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeRootPathTest(t *testing.T, apply fstest.Applier, checks []rootCheck) func(t *testing.T) {
|
func makeRootPathTest(t *testing.T, apply fstest.Applier, checks []RootCheck) func(t *testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
applyDir, err := ioutil.TempDir("", "test-root-path-")
|
applyDir, err := ioutil.TempDir("", "test-root-path-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -242,8 +242,8 @@ func makeRootPathTest(t *testing.T, apply fstest.Applier, checks []rootCheck) fu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Check(unresolved, expected string) []rootCheck {
|
func Check(unresolved, expected string) []RootCheck {
|
||||||
return []rootCheck{
|
return []RootCheck{
|
||||||
{
|
{
|
||||||
unresolved: unresolved,
|
unresolved: unresolved,
|
||||||
expected: expected,
|
expected: expected,
|
||||||
@ -251,8 +251,8 @@ func Check(unresolved, expected string) []rootCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckWithScope(unresolved, expected, scope string) []rootCheck {
|
func CheckWithScope(unresolved, expected, scope string) []RootCheck {
|
||||||
return []rootCheck{
|
return []RootCheck{
|
||||||
{
|
{
|
||||||
unresolved: unresolved,
|
unresolved: unresolved,
|
||||||
expected: expected,
|
expected: expected,
|
||||||
@ -263,8 +263,8 @@ func CheckWithScope(unresolved, expected, scope string) []rootCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrorWithScope(unresolved, scope string, cause error) []rootCheck {
|
func ErrorWithScope(unresolved, scope string, cause error) []RootCheck {
|
||||||
return []rootCheck{
|
return []RootCheck{
|
||||||
{
|
{
|
||||||
unresolved: unresolved,
|
unresolved: unresolved,
|
||||||
cause: cause,
|
cause: cause,
|
||||||
@ -275,8 +275,8 @@ func ErrorWithScope(unresolved, scope string, cause error) []rootCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAll(checks ...[]rootCheck) []rootCheck {
|
func CheckAll(checks ...[]RootCheck) []RootCheck {
|
||||||
all := make([]rootCheck, 0, len(checks))
|
all := make([]RootCheck, 0, len(checks))
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
all = append(all, c...)
|
all = append(all, c...)
|
||||||
}
|
}
|
||||||
|
2
gc/gc.go
2
gc/gc.go
@ -10,7 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resourcetype represents type of resource at a node
|
// ResourceType represents type of resource at a node
|
||||||
type ResourceType uint8
|
type ResourceType uint8
|
||||||
|
|
||||||
// Node presents a resource which has a type and key,
|
// Node presents a resource which has a type and key,
|
||||||
|
@ -190,6 +190,7 @@ func (m *DB) Update(fn func(*bolt.Tx) error) error {
|
|||||||
return m.db.Update(fn)
|
return m.db.Update(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GarbageCollect starts garbage collection
|
||||||
func (m *DB) GarbageCollect(ctx context.Context) error {
|
func (m *DB) GarbageCollect(ctx context.Context) error {
|
||||||
lt1 := time.Now()
|
lt1 := time.Now()
|
||||||
m.wlock.Lock()
|
m.wlock.Lock()
|
||||||
|
@ -12,10 +12,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// ResourceUnknown specifies an unknown resource
|
||||||
ResourceUnknown gc.ResourceType = iota
|
ResourceUnknown gc.ResourceType = iota
|
||||||
|
// ResourceContent specifies a content resource
|
||||||
ResourceContent
|
ResourceContent
|
||||||
|
// ResourceSnapshot specifies a snapshot resource
|
||||||
ResourceSnapshot
|
ResourceSnapshot
|
||||||
|
// ResourceContainer specifies a container resource
|
||||||
ResourceContainer
|
ResourceContainer
|
||||||
|
// ResourceTask specifies a task resource
|
||||||
ResourceTask
|
ResourceTask
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ type InitContext struct {
|
|||||||
|
|
||||||
Meta *Meta // plugins can fill in metadata at init.
|
Meta *Meta // plugins can fill in metadata at init.
|
||||||
|
|
||||||
plugins *PluginSet
|
plugins *Set
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContext returns a new plugin InitContext
|
// NewContext returns a new plugin InitContext
|
||||||
func NewContext(ctx context.Context, r *Registration, plugins *PluginSet, root, state string) *InitContext {
|
func NewContext(ctx context.Context, r *Registration, plugins *Set, root, state string) *InitContext {
|
||||||
return &InitContext{
|
return &InitContext{
|
||||||
Context: log.WithModule(ctx, r.URI()),
|
Context: log.WithModule(ctx, r.URI()),
|
||||||
Root: filepath.Join(root, r.URI()),
|
Root: filepath.Join(root, r.URI()),
|
||||||
@ -72,26 +72,26 @@ func (p *Plugin) Instance() (interface{}, error) {
|
|||||||
return p.instance, p.err
|
return p.instance, p.err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginSet defines a plugin collection, used with InitContext.
|
// Set defines a plugin collection, used with InitContext.
|
||||||
//
|
//
|
||||||
// This maintains ordering and unique indexing over the set.
|
// This maintains ordering and unique indexing over the set.
|
||||||
//
|
//
|
||||||
// After iteratively instantiating plugins, this set should represent, the
|
// After iteratively instantiating plugins, this set should represent, the
|
||||||
// ordered, initialization set of plugins for a containerd instance.
|
// ordered, initialization set of plugins for a containerd instance.
|
||||||
type PluginSet struct {
|
type Set struct {
|
||||||
ordered []*Plugin // order of initialization
|
ordered []*Plugin // order of initialization
|
||||||
byTypeAndID map[Type]map[string]*Plugin
|
byTypeAndID map[Type]map[string]*Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPluginSet returns an initialized plugin set
|
// NewPluginSet returns an initialized plugin set
|
||||||
func NewPluginSet() *PluginSet {
|
func NewPluginSet() *Set {
|
||||||
return &PluginSet{
|
return &Set{
|
||||||
byTypeAndID: make(map[Type]map[string]*Plugin),
|
byTypeAndID: make(map[Type]map[string]*Plugin),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a plugin to the set
|
// Add a plugin to the set
|
||||||
func (ps *PluginSet) Add(p *Plugin) error {
|
func (ps *Set) Add(p *Plugin) error {
|
||||||
if byID, typeok := ps.byTypeAndID[p.Registration.Type]; !typeok {
|
if byID, typeok := ps.byTypeAndID[p.Registration.Type]; !typeok {
|
||||||
ps.byTypeAndID[p.Registration.Type] = map[string]*Plugin{
|
ps.byTypeAndID[p.Registration.Type] = map[string]*Plugin{
|
||||||
p.Registration.ID: p,
|
p.Registration.ID: p,
|
||||||
@ -107,7 +107,7 @@ func (ps *PluginSet) Add(p *Plugin) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the first plugin by its type
|
// Get returns the first plugin by its type
|
||||||
func (ps *PluginSet) Get(t Type) (interface{}, error) {
|
func (ps *Set) Get(t Type) (interface{}, error) {
|
||||||
for _, v := range ps.byTypeAndID[t] {
|
for _, v := range ps.byTypeAndID[t] {
|
||||||
return v.Instance()
|
return v.Instance()
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,13 @@ const (
|
|||||||
|
|
||||||
// Registration contains information for registering a plugin
|
// Registration contains information for registering a plugin
|
||||||
type Registration struct {
|
type Registration struct {
|
||||||
Type Type
|
// Type of the plugin
|
||||||
ID string
|
Type Type
|
||||||
Config interface{}
|
// ID of the plugin
|
||||||
|
ID string
|
||||||
|
// Config specific to the plugin
|
||||||
|
Config interface{}
|
||||||
|
// Requires is a list of plugins that the registered plugin requires to be avaliable
|
||||||
Requires []Type
|
Requires []Type
|
||||||
|
|
||||||
// InitFn is called when initializing a plugin. The registration and
|
// InitFn is called when initializing a plugin. The registration and
|
||||||
@ -69,6 +73,7 @@ type Registration struct {
|
|||||||
InitFn func(*InitContext) (interface{}, error)
|
InitFn func(*InitContext) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init the registered plugin
|
||||||
func (r *Registration) Init(ic *InitContext) *Plugin {
|
func (r *Registration) Init(ic *InitContext) *Plugin {
|
||||||
p, err := r.InitFn(ic)
|
p, err := r.InitFn(ic)
|
||||||
return &Plugin{
|
return &Plugin{
|
||||||
|
@ -44,6 +44,6 @@ func (ra *remoteReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *remoteReaderAt) Close() error {
|
func (ra *remoteReaderAt) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ type remoteStore struct {
|
|||||||
client contentapi.ContentClient
|
client contentapi.ContentClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewStoreFromClient returns a new content store
|
||||||
func NewStoreFromClient(client contentapi.ContentClient) content.Store {
|
func NewStoreFromClient(client contentapi.ContentClient) content.Store {
|
||||||
return &remoteStore{
|
return &remoteStore{
|
||||||
client: client,
|
client: client,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewApplierFromClient returns a new Applier which communicates
|
// NewDiffServiceFromClient returns a new diff service which communicates
|
||||||
// over a GRPC connection.
|
// over a GRPC connection.
|
||||||
func NewDiffServiceFromClient(client diffapi.DiffClient) diff.Differ {
|
func NewDiffServiceFromClient(client diffapi.DiffClient) diff.Differ {
|
||||||
return &remote{
|
return &remote{
|
||||||
|
@ -13,6 +13,7 @@ type remoteStore struct {
|
|||||||
client imagesapi.ImagesClient
|
client imagesapi.ImagesClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewStoreFromClient returns a new image store client
|
||||||
func NewStoreFromClient(client imagesapi.ImagesClient) images.Store {
|
func NewStoreFromClient(client imagesapi.ImagesClient) images.Store {
|
||||||
return &remoteStore{
|
return &remoteStore{
|
||||||
client: client,
|
client: client,
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewStoreFromClient returns a new namespace store
|
||||||
func NewStoreFromClient(client api.NamespacesClient) namespaces.Store {
|
func NewStoreFromClient(client api.NamespacesClient) namespaces.Store {
|
||||||
return &remote{client: client}
|
return &remote{client: client}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,9 @@ const (
|
|||||||
KindCommitted
|
KindCommitted
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ParseKind parses the provided string into a Kind
|
||||||
|
//
|
||||||
|
// If the string cannot be parsed KindUnknown is returned
|
||||||
func ParseKind(s string) Kind {
|
func ParseKind(s string) Kind {
|
||||||
s = strings.ToLower(s)
|
s = strings.ToLower(s)
|
||||||
switch s {
|
switch s {
|
||||||
@ -34,6 +37,7 @@ func ParseKind(s string) Kind {
|
|||||||
return KindUnknown
|
return KindUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of the Kind
|
||||||
func (k Kind) String() string {
|
func (k Kind) String() string {
|
||||||
switch k {
|
switch k {
|
||||||
case KindView:
|
case KindView:
|
||||||
@ -47,10 +51,12 @@ func (k Kind) String() string {
|
|||||||
return "Unknown"
|
return "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON the Kind to JSON
|
||||||
func (k Kind) MarshalJSON() ([]byte, error) {
|
func (k Kind) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(k.String())
|
return json.Marshal(k.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON the Kind from JSON
|
||||||
func (k *Kind) UnmarshalJSON(b []byte) error {
|
func (k *Kind) UnmarshalJSON(b []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(b, &s); err != nil {
|
if err := json.Unmarshal(b, &s); err != nil {
|
||||||
@ -81,6 +87,7 @@ type Usage struct {
|
|||||||
Size int64 // provides usage, in bytes, of snapshot
|
Size int64 // provides usage, in bytes, of snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the provided usage to the current usage
|
||||||
func (u *Usage) Add(other Usage) {
|
func (u *Usage) Add(other Usage) {
|
||||||
u.Size += other.Size
|
u.Size += other.Size
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ func GetInfo(ctx context.Context, key string) (string, snapshot.Info, snapshot.U
|
|||||||
return fmt.Sprintf("%d", id), si, su, nil
|
return fmt.Sprintf("%d", id), si, su, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateInfo updates an existing snapshot info's data
|
||||||
func UpdateInfo(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
func UpdateInfo(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||||
updated := snapshot.Info{
|
updated := snapshot.Info{
|
||||||
Name: info.Name,
|
Name: info.Name,
|
||||||
@ -131,11 +132,7 @@ func UpdateInfo(ctx context.Context, info snapshot.Info, fieldpaths ...string) (
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := boltutil.WriteLabels(sbkt, updated.Labels); err != nil {
|
return boltutil.WriteLabels(sbkt, updated.Labels)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return snapshot.Info{}, err
|
return snapshot.Info{}, err
|
||||||
@ -534,12 +531,7 @@ func putSnapshot(bkt *bolt.Bucket, id uint64, si snapshot.Info) error {
|
|||||||
if err := boltutil.WriteTimestamps(bkt, si.Created, si.Updated); err != nil {
|
if err := boltutil.WriteTimestamps(bkt, si.Created, si.Updated); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return boltutil.WriteLabels(bkt, si.Labels)
|
||||||
if err := boltutil.WriteLabels(bkt, si.Labels); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUsage(bkt *bolt.Bucket, usage *snapshot.Usage) {
|
func getUsage(bkt *bolt.Bucket, usage *snapshot.Usage) {
|
||||||
@ -569,7 +561,7 @@ func putUsage(bkt *bolt.Bucket, usage snapshot.Usage) error {
|
|||||||
func encodeSize(size int64) ([]byte, error) {
|
func encodeSize(size int64) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
buf [binary.MaxVarintLen64]byte
|
buf [binary.MaxVarintLen64]byte
|
||||||
sizeEncoded []byte = buf[:]
|
sizeEncoded = buf[:]
|
||||||
)
|
)
|
||||||
sizeEncoded = sizeEncoded[:binary.PutVarint(sizeEncoded, size)]
|
sizeEncoded = sizeEncoded[:binary.PutVarint(sizeEncoded, size)]
|
||||||
|
|
||||||
|
@ -6,14 +6,17 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StatAtime returns the Atim
|
||||||
func StatAtime(st *syscall.Stat_t) syscall.Timespec {
|
func StatAtime(st *syscall.Stat_t) syscall.Timespec {
|
||||||
return st.Atim
|
return st.Atim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatCtime returns the Ctim
|
||||||
func StatCtime(st *syscall.Stat_t) syscall.Timespec {
|
func StatCtime(st *syscall.Stat_t) syscall.Timespec {
|
||||||
return st.Ctim
|
return st.Ctim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatMtime returns the Mtim
|
||||||
func StatMtime(st *syscall.Stat_t) syscall.Timespec {
|
func StatMtime(st *syscall.Stat_t) syscall.Timespec {
|
||||||
return st.Mtim
|
return st.Mtim
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user