From 2babdce1a1b5a7e4e19c380a895bb648877d3fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 20 Jun 2023 15:07:10 +0200 Subject: [PATCH] Make the linters happy --- pkg/storage/utils/decomposedfs/decomposedfs.go | 12 ------------ pkg/storage/utils/decomposedfs/grants_test.go | 9 --------- .../0004_switch_to_messagepack_space_index.go | 2 +- .../decomposedfs/spaceidindex/spaceidindex.go | 16 ++++++++++------ pkg/storage/utils/decomposedfs/spaces.go | 12 ++++++------ 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index ecd950ec92d..b69f624e266 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -32,7 +32,6 @@ import ( "path/filepath" "strconv" "strings" - "syscall" "time" rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" @@ -525,17 +524,6 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) { return nil } -// The os not exists error is buried inside the xattr error, -// so we cannot just use os.IsNotExists(). -func isAlreadyExists(err error) bool { - if xerr, ok := err.(*os.LinkError); ok { - if serr, ok2 := xerr.Err.(syscall.Errno); ok2 { - return serr == syscall.EEXIST - } - } - return false -} - // GetHome is called to look up the home path for a user // It is NOT supposed to return the internal path but the external path func (fs *Decomposedfs) GetHome(ctx context.Context) (string, error) { diff --git a/pkg/storage/utils/decomposedfs/grants_test.go b/pkg/storage/utils/decomposedfs/grants_test.go index e3564e69d74..f2bc8c131e6 100644 --- a/pkg/storage/utils/decomposedfs/grants_test.go +++ b/pkg/storage/utils/decomposedfs/grants_test.go @@ -20,7 +20,6 @@ package decomposedfs_test import ( "fmt" - "io/fs" "os" "path/filepath" @@ -33,14 +32,6 @@ import ( "github.com/stretchr/testify/mock" ) -type testFS struct { - root string -} - -func (t testFS) Open(name string) (fs.File, error) { - return os.Open(filepath.Join(t.root, name)) -} - var _ = Describe("Grants", func() { var ( env *helpers.TestEnv diff --git a/pkg/storage/utils/decomposedfs/migrator/0004_switch_to_messagepack_space_index.go b/pkg/storage/utils/decomposedfs/migrator/0004_switch_to_messagepack_space_index.go index abcfc887c2d..43f36244e4b 100644 --- a/pkg/storage/utils/decomposedfs/migrator/0004_switch_to_messagepack_space_index.go +++ b/pkg/storage/utils/decomposedfs/migrator/0004_switch_to_messagepack_space_index.go @@ -112,7 +112,7 @@ func migrateSpaceIndex(indexPath, dirIndexPath, cacheKey string) error { if err != nil { return err } - os.WriteFile(indexPath, d, 0600) + err = os.WriteFile(indexPath, d, 0600) if err != nil { return err } diff --git a/pkg/storage/utils/decomposedfs/spaceidindex/spaceidindex.go b/pkg/storage/utils/decomposedfs/spaceidindex/spaceidindex.go index 91f9c6bf4d6..4d9add38951 100644 --- a/pkg/storage/utils/decomposedfs/spaceidindex/spaceidindex.go +++ b/pkg/storage/utils/decomposedfs/spaceidindex/spaceidindex.go @@ -12,6 +12,7 @@ import ( "github.com/shamaton/msgpack/v2" ) +// Index holds space id indexes type Index struct { root string name string @@ -24,6 +25,7 @@ type readWriteCloseSeekTruncater interface { Truncate(int64) error } +// New returns a new index instance func New(root, name string) *Index { return &Index{ root: root, @@ -31,11 +33,13 @@ func New(root, name string) *Index { } } +// Init initializes the index and makes sure it can be used func (i *Index) Init() error { // Make sure to work on an existing tree return os.MkdirAll(filepath.Join(i.root, i.name), 0700) } +// Load returns the content of an index func (i *Index) Load(index string) (map[string]string, error) { indexPath := filepath.Join(i.root, i.name, index+".mpk") fi, err := os.Stat(indexPath) @@ -45,21 +49,21 @@ func (i *Index) Load(index string) (map[string]string, error) { return i.readSpaceIndex(indexPath, i.name+":"+index, fi.ModTime()) } -// func (i *Index) RemoveFromIndex(key, entry string) os.LinkError { - +// Add adds an entry to an index func (i *Index) Add(index, key string, value string) error { - return i.UpdateIndex(index, map[string]string{key: value}, []string{}) + return i.updateIndex(index, map[string]string{key: value}, []string{}) } +// Remove removes an entry from the index func (i *Index) Remove(index, key string) error { - return i.UpdateIndex(index, map[string]string{}, []string{key}) + return i.updateIndex(index, map[string]string{}, []string{key}) } -func (i *Index) UpdateIndex(index string, addLinks map[string]string, removeLinks []string) error { +func (i *Index) updateIndex(index string, addLinks map[string]string, removeLinks []string) error { indexPath := filepath.Join(i.root, i.name, index+".mpk") var err error - // aquire writelock + // acquire writelock var f readWriteCloseSeekTruncater f, err = lockedfile.OpenFile(indexPath, os.O_RDWR|os.O_CREATE, 0600) if err != nil { diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index 95fe8bd8d06..d9b51deaf64 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -310,10 +310,10 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide if nodeID == spaceIDAny { for _, match := range allMatches { - matches[string(match)] = struct{}{} + matches[match] = struct{}{} } } else { - matches[string(allMatches[nodeID])] = struct{}{} + matches[allMatches[nodeID]] = struct{}{} } // get Groups for userid @@ -337,10 +337,10 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide if nodeID == spaceIDAny { for _, match := range allMatches { - matches[string(match)] = struct{}{} + matches[match] = struct{}{} } } else { - matches[string(allMatches[nodeID])] = struct{}{} + matches[allMatches[nodeID]] = struct{}{} } } @@ -367,10 +367,10 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide if nodeID == spaceIDAny { for _, match := range allMatches { - matches[string(match)] = struct{}{} + matches[match] = struct{}{} } } else { - matches[string(allMatches[nodeID])] = struct{}{} + matches[allMatches[nodeID]] = struct{}{} } } }