fix(files): fix small issues

This commit is contained in:
hexxa 2021-09-12 22:27:56 +08:00 committed by Hexxa
parent 70318be81d
commit fb9de35e81
2 changed files with 15 additions and 1 deletions

View file

@ -25,6 +25,7 @@ type LocalFS struct {
opensMtx *sync.RWMutex
opensCleanSize int
openTTL time.Duration
readersMtx *sync.RWMutex
readers map[string]*fileInfo
}
@ -47,6 +48,7 @@ func NewLocalFS(root string, defaultPerm uint32, opensLimit, openTTL int) *Local
openTTL: time.Duration(openTTL) * time.Second,
opensMtx: &sync.RWMutex{},
opensCleanSize: 10,
readersMtx: &sync.RWMutex{},
readers: map[string]*fileInfo{}, // TODO: track readers and close idles
}
}
@ -307,6 +309,9 @@ func (fs *LocalFS) GetFileReader(path string) (fs.ReadCloseSeeker, error) {
return nil, err
}
fs.readersMtx.Lock()
defer fs.readersMtx.Unlock()
fs.readers[fullpath] = &fileInfo{
fd: fd,
lastAccess: time.Now(),