Fix wsl lint errors in kopia package (#650)
This commit is contained in:
parent
f1370b36e4
commit
c4e9046870
@ -71,6 +71,7 @@ func (w *conn) Initialize(ctx context.Context) error {
|
|||||||
if errors.Is(err, repo.ErrAlreadyInitialized) {
|
if errors.Is(err, repo.ErrAlreadyInitialized) {
|
||||||
return RepoAlreadyExistsError(err)
|
return RepoAlreadyExistsError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Wrap(err, errInit.Error())
|
return errors.Wrap(err, errInit.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +190,7 @@ func (w *conn) open(ctx context.Context, configPath, password string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.Repository = rep
|
w.Repository = rep
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +203,7 @@ func (w *conn) wrap() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.refCount++
|
w.refCount++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,8 +38,8 @@ func TestWrapperUnitSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (suite *WrapperUnitSuite) TestCloseWithoutOpenDoesNotCrash() {
|
func (suite *WrapperUnitSuite) TestCloseWithoutOpenDoesNotCrash() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
k := conn{}
|
k := conn{}
|
||||||
|
|
||||||
assert.NotPanics(suite.T(), func() {
|
assert.NotPanics(suite.T(), func() {
|
||||||
k.Close(ctx)
|
k.Close(ctx)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -18,6 +18,7 @@ type kopiaDataCollection struct {
|
|||||||
|
|
||||||
func (kdc *kopiaDataCollection) Items() <-chan data.Stream {
|
func (kdc *kopiaDataCollection) Items() <-chan data.Stream {
|
||||||
res := make(chan data.Stream)
|
res := make(chan data.Stream)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(res)
|
defer close(res)
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ func NewModelStore(c *conn) (*ModelStore, error) {
|
|||||||
if err := c.wrap(); err != nil {
|
if err := c.wrap(); err != nil {
|
||||||
return nil, errors.Wrap(err, "creating ModelStore")
|
return nil, errors.Wrap(err, "creating ModelStore")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ModelStore{c: c}, nil
|
return &ModelStore{c: c}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ func tagsForModel(s model.Schema, tags map[string]string) (map[string]string, er
|
|||||||
|
|
||||||
res := make(map[string]string, len(tags)+1)
|
res := make(map[string]string, len(tags)+1)
|
||||||
res[manifest.TypeLabelKey] = s.String()
|
res[manifest.TypeLabelKey] = s.String()
|
||||||
|
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
res[k] = v
|
res[k] = v
|
||||||
}
|
}
|
||||||
@ -122,6 +124,7 @@ func putInner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
base.ModelStoreID = id
|
base.ModelStoreID = id
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +138,7 @@ func (ms *ModelStore) Put(
|
|||||||
if !s.Valid() {
|
if !s.Valid() {
|
||||||
return errors.WithStack(errUnrecognizedSchema)
|
return errors.WithStack(errUnrecognizedSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := repo.WriteSession(
|
err := repo.WriteSession(
|
||||||
ctx,
|
ctx,
|
||||||
ms.c,
|
ms.c,
|
||||||
@ -170,6 +174,7 @@ func baseModelFromMetadata(m *manifest.EntryMetadata) (*model.BaseModel, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
stripHiddenTags(res.Tags)
|
stripHiddenTags(res.Tags)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +205,7 @@ func (ms *ModelStore) GetIDsForType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
res := make([]*model.BaseModel, 0, len(metadata))
|
res := make([]*model.BaseModel, 0, len(metadata))
|
||||||
|
|
||||||
for _, m := range metadata {
|
for _, m := range metadata {
|
||||||
bm, err := baseModelFromMetadata(m)
|
bm, err := baseModelFromMetadata(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -230,6 +236,7 @@ func (ms *ModelStore) getModelStoreID(
|
|||||||
}
|
}
|
||||||
|
|
||||||
tags := map[string]string{stableIDKey: string(id)}
|
tags := map[string]string{stableIDKey: string(id)}
|
||||||
|
|
||||||
metadata, err := ms.c.FindManifests(ctx, tags)
|
metadata, err := ms.c.FindManifests(ctx, tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "getting ModelStoreID")
|
return "", errors.Wrap(err, "getting ModelStoreID")
|
||||||
@ -238,9 +245,11 @@ func (ms *ModelStore) getModelStoreID(
|
|||||||
if len(metadata) == 0 {
|
if len(metadata) == 0 {
|
||||||
return "", errors.Wrap(manifest.ErrNotFound, "getting ModelStoreID")
|
return "", errors.Wrap(manifest.ErrNotFound, "getting ModelStoreID")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(metadata) != 1 {
|
if len(metadata) != 1 {
|
||||||
return "", errors.New("multiple models with same StableID")
|
return "", errors.New("multiple models with same StableID")
|
||||||
}
|
}
|
||||||
|
|
||||||
if metadata[0].Labels[manifest.TypeLabelKey] != s.String() {
|
if metadata[0].Labels[manifest.TypeLabelKey] != s.String() {
|
||||||
return "", errors.WithStack(errModelTypeMismatch)
|
return "", errors.WithStack(errModelTypeMismatch)
|
||||||
}
|
}
|
||||||
@ -303,6 +312,7 @@ func (ms *ModelStore) GetWithModelStoreID(
|
|||||||
base.Tags = metadata.Labels
|
base.Tags = metadata.Labels
|
||||||
stripHiddenTags(base.Tags)
|
stripHiddenTags(base.Tags)
|
||||||
base.ModelStoreID = id
|
base.ModelStoreID = id
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +344,7 @@ func (ms *ModelStore) checkPrevModelVersion(
|
|||||||
if meta.ID != b.ModelStoreID {
|
if meta.ID != b.ModelStoreID {
|
||||||
return errors.New("updated model has different ModelStoreID")
|
return errors.New("updated model has different ModelStoreID")
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Labels[manifest.TypeLabelKey] != s.String() {
|
if meta.Labels[manifest.TypeLabelKey] != s.String() {
|
||||||
return errors.New("updated model has different model type")
|
return errors.New("updated model has different model type")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,10 +18,12 @@ func s3BlobStorage(ctx context.Context, s storage.Storage) (blob.Storage, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := defaultS3Endpoint
|
endpoint := defaultS3Endpoint
|
||||||
if len(cfg.Endpoint) > 0 {
|
if len(cfg.Endpoint) > 0 {
|
||||||
endpoint = cfg.Endpoint
|
endpoint = cfg.Endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := s3.Options{
|
opts := s3.Options{
|
||||||
AccessKeyID: cfg.AccessKey,
|
AccessKeyID: cfg.AccessKey,
|
||||||
BucketName: cfg.Bucket,
|
BucketName: cfg.Bucket,
|
||||||
@ -30,5 +32,6 @@ func s3BlobStorage(ctx context.Context, s storage.Storage) (blob.Storage, error)
|
|||||||
SecretAccessKey: cfg.SecretKey,
|
SecretAccessKey: cfg.SecretKey,
|
||||||
SessionToken: cfg.SessionToken,
|
SessionToken: cfg.SessionToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
return s3.New(ctx, &opts)
|
return s3.New(ctx, &opts)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,6 +107,7 @@ func NewWrapper(c *conn) (*Wrapper, error) {
|
|||||||
if err := c.wrap(); err != nil {
|
if err := c.wrap(); err != nil {
|
||||||
return nil, errors.Wrap(err, "creating Wrapper")
|
return nil, errors.Wrap(err, "creating Wrapper")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Wrapper{c}, nil
|
return &Wrapper{c}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +152,7 @@ func getStreamItemFunc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
items := streamedEnts.Items()
|
items := streamedEnts.Items()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@ -293,6 +295,7 @@ func inflateDirTree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var res fs.Directory
|
var res fs.Directory
|
||||||
|
|
||||||
for dirName, dir := range roots {
|
for dirName, dir := range roots {
|
||||||
tmp, err := buildKopiaDirs(dirName, dir, progress)
|
tmp, err := buildKopiaDirs(dirName, dir, progress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -397,6 +400,7 @@ func (w Wrapper) makeSnapshotWithRoot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
res := manifestToStats(man)
|
res := manifestToStats(man)
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,9 +532,10 @@ func walkDirectory(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
dir fs.Directory,
|
dir fs.Directory,
|
||||||
) ([]fs.File, []fs.Directory, *multierror.Error) {
|
) ([]fs.File, []fs.Directory, *multierror.Error) {
|
||||||
|
var errs *multierror.Error
|
||||||
|
|
||||||
files := []fs.File{}
|
files := []fs.File{}
|
||||||
dirs := []fs.Directory{}
|
dirs := []fs.Directory{}
|
||||||
var errs *multierror.Error
|
|
||||||
|
|
||||||
err := dir.IterateEntries(ctx, func(innerCtx context.Context, e fs.Entry) error {
|
err := dir.IterateEntries(ctx, func(innerCtx context.Context, e fs.Entry) error {
|
||||||
// Early exit on context cancel.
|
// Early exit on context cancel.
|
||||||
@ -569,10 +574,11 @@ func restoreSubtree(
|
|||||||
dir fs.Directory,
|
dir fs.Directory,
|
||||||
relativePath []string,
|
relativePath []string,
|
||||||
) ([]data.Collection, *multierror.Error) {
|
) ([]data.Collection, *multierror.Error) {
|
||||||
|
var errs *multierror.Error
|
||||||
|
|
||||||
collections := []data.Collection{}
|
collections := []data.Collection{}
|
||||||
// Want a local copy of relativePath with our new element.
|
// Want a local copy of relativePath with our new element.
|
||||||
fullPath := append(append([]string{}, relativePath...), dir.Name())
|
fullPath := append(append([]string{}, relativePath...), dir.Name())
|
||||||
var errs *multierror.Error
|
|
||||||
|
|
||||||
files, dirs, err := walkDirectory(ctx, dir)
|
files, dirs, err := walkDirectory(ctx, dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -594,8 +600,10 @@ func restoreSubtree(
|
|||||||
fileFullPath := path.Join(append(append([]string{}, fullPath...), f.Name())...)
|
fileFullPath := path.Join(append(append([]string{}, fullPath...), f.Name())...)
|
||||||
errs = multierror.Append(
|
errs = multierror.Append(
|
||||||
errs, errors.Wrapf(err, "getting reader for file %q", fileFullPath))
|
errs, errors.Wrapf(err, "getting reader for file %q", fileFullPath))
|
||||||
|
|
||||||
logger.Ctx(ctx).Errorw(
|
logger.Ctx(ctx).Errorw(
|
||||||
"unable to get file reader; skipping", "path", fileFullPath)
|
"unable to get file reader; skipping", "path", fileFullPath)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,6 +664,7 @@ func (w Wrapper) RestoreMultipleItems(
|
|||||||
dcs = []data.Collection{}
|
dcs = []data.Collection{}
|
||||||
errs *multierror.Error
|
errs *multierror.Error
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, itemPath := range paths {
|
for _, itemPath := range paths {
|
||||||
dc, err := w.RestoreSingleItem(ctx, snapshotID, itemPath)
|
dc, err := w.RestoreSingleItem(ctx, snapshotID, itemPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -664,6 +673,7 @@ func (w Wrapper) RestoreMultipleItems(
|
|||||||
dcs = append(dcs, dc)
|
dcs = append(dcs, dc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dcs, errs.ErrorOrNil()
|
return dcs, errs.ErrorOrNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,7 @@ func testForFiles(
|
|||||||
collections []data.Collection,
|
collections []data.Collection,
|
||||||
) {
|
) {
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
for _, c := range collections {
|
for _, c := range collections {
|
||||||
for s := range c.Items() {
|
for s := range c.Items() {
|
||||||
count++
|
count++
|
||||||
@ -228,6 +229,7 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree() {
|
|||||||
|
|
||||||
entries, err := fs.GetAllEntries(ctx, dirTree)
|
entries, err := fs.GetAllEntries(ctx, dirTree)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
names := entriesToNames(entries)
|
names := entriesToNames(entries)
|
||||||
assert.Len(suite.T(), names, 2)
|
assert.Len(suite.T(), names, 2)
|
||||||
assert.Contains(suite.T(), names, user1)
|
assert.Contains(suite.T(), names, user1)
|
||||||
@ -261,7 +263,6 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree_NoAncestorDirs() {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
emails := "emails"
|
emails := "emails"
|
||||||
|
|
||||||
expectedFileCount := 42
|
expectedFileCount := 42
|
||||||
|
|
||||||
progress := &corsoProgress{pending: map[string]*itemDetails{}}
|
progress := &corsoProgress{pending: map[string]*itemDetails{}}
|
||||||
@ -537,8 +538,10 @@ func (suite *KopiaIntegrationSuite) SetupSuite() {
|
|||||||
func (suite *KopiaIntegrationSuite) SetupTest() {
|
func (suite *KopiaIntegrationSuite) SetupTest() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
suite.ctx = context.Background()
|
suite.ctx = context.Background()
|
||||||
|
|
||||||
c, err := openKopiaRepo(t, suite.ctx)
|
c, err := openKopiaRepo(t, suite.ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
suite.w = &Wrapper{c}
|
suite.w = &Wrapper{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,6 +763,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) SetupTest() {
|
|||||||
for k, v := range suite.inboxExpectedFiles {
|
for k, v := range suite.inboxExpectedFiles {
|
||||||
suite.allExpectedFiles[k] = v
|
suite.allExpectedFiles[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range suite.archiveExpectedFiles {
|
for k, v := range suite.archiveExpectedFiles {
|
||||||
suite.allExpectedFiles[k] = v
|
suite.allExpectedFiles[k] = v
|
||||||
}
|
}
|
||||||
@ -782,6 +786,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) TestBackupAndRestoreSingleItem() {
|
|||||||
assert.Equal(t, c.FullPath(), testPath)
|
assert.Equal(t, c.FullPath(), testPath)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
for resultStream := range c.Items() {
|
for resultStream := range c.Items() {
|
||||||
buf, err := ioutil.ReadAll(resultStream.ToReader())
|
buf, err := ioutil.ReadAll(resultStream.ToReader())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -925,6 +930,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) TestRestoreMultipleItems() {
|
|||||||
p2 := []string{tid, "uid2", "emails", "fid"}
|
p2 := []string{tid, "uid2", "emails", "fid"}
|
||||||
dc1 := mockconnector.NewMockExchangeCollection(p1, 1)
|
dc1 := mockconnector.NewMockExchangeCollection(p1, 1)
|
||||||
dc2 := mockconnector.NewMockExchangeCollection(p2, 1)
|
dc2 := mockconnector.NewMockExchangeCollection(p2, 1)
|
||||||
|
|
||||||
fp1 := append(p1, dc1.Names[0])
|
fp1 := append(p1, dc1.Names[0])
|
||||||
fp2 := append(p2, dc2.Names[0])
|
fp2 := append(p2, dc2.Names[0])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user