Skip to content

Commit

Permalink
fix: dont do useless netreads
Browse files Browse the repository at this point in the history
  • Loading branch information
likeazir committed Oct 9, 2023
1 parent f6f1724 commit d971816
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/pkg/cacheclient/cacheclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/rs/zerolog/log"
"io/fs"
"path/filepath"
"readnetfs/internal/pkg/fsclient"
"sync"
"syscall"
Expand Down Expand Up @@ -107,7 +106,19 @@ func (c *CacheClient) ReadDir(path fsclient.RemotePath) ([]fs.FileInfo, error) {

func (c *CacheClient) FileInfo(path fsclient.RemotePath) (fs.FileInfo, error) {
//trigger parent dir read to fill cache for future requests
go c.ReadDir(fsclient.RemotePath(filepath.Dir(string(path))))
func() {
c.dirContentLock.Lock()
defer c.dirContentLock.Unlock()
infos, err := c.client.ReadDir(path)
if err != nil {
return
}
files := make([]string, len(infos))
for i, info := range infos {
files[i] = info.Name()
c.infos.Add(path.Append(info.Name()), info)
}
}()
if info, ok := c.infos.Get(path); ok {
return info, nil
}
Expand Down

0 comments on commit d971816

Please sign in to comment.