Skip to content

Commit

Permalink
fix(ci): golangci
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Dec 8, 2024
1 parent 638cce8 commit 75cc6df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/registered.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var registered = sync.Map{}

func RegisterStorage(s Storer) {
s.Init()
_ = s.Init()
registered.Store(fmt.Sprintf("%s-%s", s.Name(), s.Uuid()), s)
}

Expand Down
23 changes: 11 additions & 12 deletions simplefs/simplefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (provider *Simplefs) recoverEnoughSpaceIfNeeded(size int64) {
if provider.directorySize > -1 && provider.actualSize+size > provider.directorySize {
provider.cache.RangeBackwards(func(item *ttlcache.Item[string, []byte]) bool {
// Remove the oldest item if there is not enough space.
//nolint:godox
// TODO: open a PR to expose a range that iterate on LRU items.
provider.cache.Delete(string(item.Value()))

Expand All @@ -184,8 +185,6 @@ func (provider *Simplefs) recoverEnoughSpaceIfNeeded(size int64) {

provider.recoverEnoughSpaceIfNeeded(size)
}

return
}

// SetMultiLevel tries to store the key with the given value and update the mapping key to store metadata.
Expand Down Expand Up @@ -267,14 +266,14 @@ func (provider *Simplefs) DeleteMany(key string) {

// Init method will.
func (provider *Simplefs) Init() error {
provider.cache.OnInsertion(func(_ context.Context, i *ttlcache.Item[string, []byte]) {
if strings.Contains(string(i.Key()), core.MappingKeyPrefix) {
provider.cache.OnInsertion(func(_ context.Context, item *ttlcache.Item[string, []byte]) {
if strings.Contains(item.Key(), core.MappingKeyPrefix) {
return
}

info, err := os.Stat(string(i.Value()))
info, err := os.Stat(string(item.Value()))
if err != nil {
provider.logger.Errorf("impossible to get the file size %s: %#v", i.Key(), err)
provider.logger.Errorf("impossible to get the file size %s: %#v", item.Key(), err)

return
}
Expand All @@ -285,14 +284,14 @@ func (provider *Simplefs) Init() error {
provider.mu.Unlock()
})

provider.cache.OnEviction(func(_ context.Context, _ ttlcache.EvictionReason, i *ttlcache.Item[string, []byte]) {
if strings.Contains(string(i.Value()), core.MappingKeyPrefix) {
provider.cache.OnEviction(func(_ context.Context, _ ttlcache.EvictionReason, item *ttlcache.Item[string, []byte]) {
if strings.Contains(string(item.Value()), core.MappingKeyPrefix) {
return
}

info, err := os.Stat(string(i.Value()))
info, err := os.Stat(string(item.Value()))
if err != nil {
provider.logger.Errorf("impossible to get the file size %s: %#v", i.Key(), err)
provider.logger.Errorf("impossible to get the file size %s: %#v", item.Key(), err)

return
}
Expand All @@ -302,8 +301,8 @@ func (provider *Simplefs) Init() error {
provider.logger.Debugf("Actual size remove: %d", provider.actualSize, info.Size())
provider.mu.Unlock()

if err := onEvict(string(i.Value())); err != nil {
provider.logger.Errorf("impossible to remove the file %s: %#v", i.Key(), err)
if err := onEvict(string(item.Value())); err != nil {
provider.logger.Errorf("impossible to remove the file %s: %#v", item.Key(), err)
}
})

Expand Down
4 changes: 2 additions & 2 deletions simplefs/simplefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func TestSimplefs_Init(t *testing.T) {

func TestSimplefs_EvictAfterXSeconds(t *testing.T) {
client, _ := getSimplefsInstance()
client.Init()
_ = client.Init()

for i := 0; i < 10; i++ {
for i := range 10 {
key := fmt.Sprintf("Test_%d", i)
_ = client.SetMultiLevel(key, key, []byte(baseValue), http.Header{}, "", 1*time.Second, key)
}
Expand Down

0 comments on commit 75cc6df

Please sign in to comment.