From 35aeb0ae6c58dc84eb26c4bebd5310c54dbd3b59 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 7 Feb 2025 22:51:55 +0100 Subject: [PATCH] GO-4146 Fix some lint errors --- cmd/debugtree/debugtree.go | 2 +- core/application/account_store_migrate.go | 6 +++++- core/debug/treeexporter.go | 4 ++-- space/clientspace/space.go | 5 ++++- space/spacecore/storage/anystorage/clientstorage.go | 4 ++-- space/spacecore/storage/anystorage/storageservice.go | 5 ++--- space/spacecore/storage/migrator/migrator.go | 2 -- space/spacecore/storage/sqlitestorage/service.go | 1 + space/spacecore/storage/sqlitestorage/space.go | 5 ----- space/spacecore/storage/sqlitestorage/tree.go | 7 ------- space/spacecore/storage/sqlitestorage/tree_test.go | 5 +++++ util/ziputil/ziputil.go | 2 ++ 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd/debugtree/debugtree.go b/cmd/debugtree/debugtree.go index f5f6198cd..9ac3b88f1 100644 --- a/cmd/debugtree/debugtree.go +++ b/cmd/debugtree/debugtree.go @@ -132,11 +132,11 @@ func main() { if err != nil { log.Fatal("can't open objectStore info:", err) } - defer f.Close() info := &model.ObjectInfo{} if err = jsonpb.Unmarshal(f, info); err != nil { log.Fatal("can't unmarshal objectStore info:", err) } + defer f.Close() fmt.Println(pbtypes.Sprint(info)) } diff --git a/core/application/account_store_migrate.go b/core/application/account_store_migrate.go index 2f7f2a49d..838c98987 100644 --- a/core/application/account_store_migrate.go +++ b/core/application/account_store_migrate.go @@ -8,6 +8,7 @@ import ( "sync" "github.com/anyproto/any-sync/app" + "go.uber.org/zap" "github.com/anyproto/anytype-heart/core/anytype" "github.com/anyproto/anytype-heart/core/anytype/config" @@ -106,7 +107,10 @@ func (m *migration) setFinished(err error, notify bool) { func (m *migration) cancelMigration() { m.cancel() - _ = m.wait() + err := m.wait() + if err != nil { + log.Warn("failed to wait for migration to finish", zap.Error(err)) + } } func (m *migration) wait() error { diff --git a/core/debug/treeexporter.go b/core/debug/treeexporter.go index 43eba2e58..ba23643e5 100644 --- a/core/debug/treeexporter.go +++ b/core/debug/treeexporter.go @@ -83,7 +83,7 @@ func (e *treeExporter) Export(ctx context.Context, path string, tree objecttree. data[0].Relations[i] = transform(r, e.anonymized, anonymize.Relation) } osData := pbtypes.Sprint(data[0].ToProto()) - er := os.WriteFile(localStorePath, []byte(osData), 0644) + er := os.WriteFile(localStorePath, []byte(osData), 0600) if er != nil { e.log.Printf("localstore.json write error: %v", err) } else { @@ -93,7 +93,7 @@ func (e *treeExporter) Export(ctx context.Context, path string, tree objecttree. e.log.Printf("no data in objectstore") } } - err = os.WriteFile(logPath, logBuf.Bytes(), 0644) + err = os.WriteFile(logPath, logBuf.Bytes(), 0600) if err != nil { return } diff --git a/space/clientspace/space.go b/space/clientspace/space.go index 78eff995d..c478d4b8f 100644 --- a/space/clientspace/space.go +++ b/space/clientspace/space.go @@ -345,7 +345,10 @@ func (s *space) migrationProfileObject(ctx context.Context) error { return err } - extractedProfileExists, _ := s.Storage().HasTree(ctx, extractedProfileId) + extractedProfileExists, err := s.Storage().HasTree(ctx, extractedProfileId) + if err != nil { + return err + } if extractedProfileExists { return nil } diff --git a/space/spacecore/storage/anystorage/clientstorage.go b/space/spacecore/storage/anystorage/clientstorage.go index 7cea5b048..bbf573350 100644 --- a/space/spacecore/storage/anystorage/clientstorage.go +++ b/space/spacecore/storage/anystorage/clientstorage.go @@ -132,8 +132,8 @@ func (r *clientStorage) modifyState(ctx context.Context, isCreated bool) error { }) _, err = r.clientColl.UpsertId(tx.Context(), clientDocumentKey, mod) if err != nil { - tx.Rollback() - return err + rollErr := tx.Rollback() + return errors.Join(err, rollErr) } return tx.Commit() } diff --git a/space/spacecore/storage/anystorage/storageservice.go b/space/spacecore/storage/anystorage/storageservice.go index cedd26a0e..bf7b8460d 100644 --- a/space/spacecore/storage/anystorage/storageservice.go +++ b/space/spacecore/storage/anystorage/storageservice.go @@ -11,10 +11,10 @@ import ( anystore "github.com/anyproto/any-store" "github.com/anyproto/any-sync/app" "github.com/anyproto/any-sync/app/logger" - "github.com/anyproto/any-sync/app/ocache" "github.com/anyproto/any-sync/commonspace/spacestorage" ) +// nolint: unused var log = logger.NewNamed(spacestorage.CName) func New(rootPath string) *storageService { @@ -25,14 +25,13 @@ func New(rootPath string) *storageService { type storageService struct { rootPath string - cache ocache.OCache } func (s *storageService) AllSpaceIds() (ids []string, err error) { var files []string fileInfo, err := os.ReadDir(s.rootPath) if err != nil { - return files, fmt.Errorf("can't read datadir '%v': %v", s.rootPath, err) + return files, fmt.Errorf("can't read datadir '%v': %w", s.rootPath, err) } for _, file := range fileInfo { if !strings.HasPrefix(file.Name(), ".") { diff --git a/space/spacecore/storage/migrator/migrator.go b/space/spacecore/storage/migrator/migrator.go index 368343d74..249cb7616 100644 --- a/space/spacecore/storage/migrator/migrator.go +++ b/space/spacecore/storage/migrator/migrator.go @@ -41,7 +41,6 @@ type migrator struct { newStorage storage.ClientStorage process process.Service path string - oldPath string objectStorePath string finisher migratorfinisher.Service @@ -62,7 +61,6 @@ func New() app.ComponentRunnable { func (m *migrator) Init(a *app.App) (err error) { cfg := a.MustComponent("config").(pathProvider) m.path = cfg.GetNewSpaceStorePath() - m.oldPath = cfg.GetOldSpaceStorePath() m.objectStorePath = filepath.Join(cfg.GetRepoPath(), "objectstore") m.oldStorage = app.MustComponent[oldstorage.ClientStorage](a) m.newStorage = app.MustComponent[storage.ClientStorage](a) diff --git a/space/spacecore/storage/sqlitestorage/service.go b/space/spacecore/storage/sqlitestorage/service.go index 860f34cc4..9f88ec5f3 100644 --- a/space/spacecore/storage/sqlitestorage/service.go +++ b/space/spacecore/storage/sqlitestorage/service.go @@ -381,6 +381,7 @@ func (s *storageService) EstimateSize() (uint64, error) { if err != nil { return 0, err } + // nolint: gosec return uint64(stat.Size()), nil } diff --git a/space/spacecore/storage/sqlitestorage/space.go b/space/spacecore/storage/sqlitestorage/space.go index 2e15dc8c7..20af7caf5 100644 --- a/space/spacecore/storage/sqlitestorage/space.go +++ b/space/spacecore/storage/sqlitestorage/space.go @@ -39,11 +39,6 @@ type spaceStorage struct { header *spacesyncproto.RawSpaceHeaderWithId } -type oldTreeStorage interface { - oldstorage.ChangesIterator - oldstorage.TreeStorage -} - func newSpaceStorage(s *storageService, spaceId string) (oldstorage.SpaceStorage, error) { ss := &spaceStorage{ spaceId: spaceId, diff --git a/space/spacecore/storage/sqlitestorage/tree.go b/space/spacecore/storage/sqlitestorage/tree.go index bd9882fc7..a0994e717 100644 --- a/space/spacecore/storage/sqlitestorage/tree.go +++ b/space/spacecore/storage/sqlitestorage/tree.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "sync" - "sync/atomic" "github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto" "github.com/anyproto/any-sync/commonspace/object/tree/treestorage" @@ -205,14 +204,8 @@ func (t *treeStorage) AddRawChangesSetHeads(changes []*treechangeproto.RawTreeCh return nil } -var totalCalls atomic.Int32 - func (t *treeStorage) GetRawChange(ctx context.Context, id string) (*treechangeproto.RawTreeChangeWithId, error) { ch, err := t.spaceStorage.TreeRoot(id) - // totalCalls.Store(totalCalls.Load() + 1) - // if totalCalls.Load()%10 == 0 { - // fmt.Println("totalCalls", totalCalls.Load()) - // } if err != nil { return nil, replaceNoRowsErr(err, treestorage.ErrUnknownChange) } diff --git a/space/spacecore/storage/sqlitestorage/tree_test.go b/space/spacecore/storage/sqlitestorage/tree_test.go index 347d737c1..5ea1fc8fe 100644 --- a/space/spacecore/storage/sqlitestorage/tree_test.go +++ b/space/spacecore/storage/sqlitestorage/tree_test.go @@ -16,6 +16,11 @@ import ( "github.com/stretchr/testify/require" ) +type oldTreeStorage interface { + oldstorage.ChangesIterator + oldstorage.TreeStorage +} + func TestTreeStorage_Create(t *testing.T) { fx := newFixture(t) defer fx.finish(t) diff --git a/util/ziputil/ziputil.go b/util/ziputil/ziputil.go index 60f97de04..34f93b361 100644 --- a/util/ziputil/ziputil.go +++ b/util/ziputil/ziputil.go @@ -57,6 +57,7 @@ func UnzipFolder(sourceZip, targetDir string) error { return err } for _, file := range r.File { + // nolint: gosec extractedPath := filepath.Join(targetDir, file.Name) if file.FileInfo().IsDir() { if err := os.MkdirAll(extractedPath, 0700); err != nil { @@ -82,6 +83,7 @@ func extractFile(file *zip.File, outputPath string) error { return err } defer outputFile.Close() + // nolint: gosec _, err = io.Copy(outputFile, rc) return err }