Commit aed5935e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use struct{} as value-type in dircache map

parent b7c768d4
......@@ -15,21 +15,21 @@ import (
// newDirnameMap reads the contents of the given directory. On error,
// returns a nil map. This forces reloads in the dirCache until we
// succeed.
func newDirnameMap(fs pathfs.FileSystem, dir string) map[string]bool {
func newDirnameMap(fs pathfs.FileSystem, dir string) map[string]struct{} {
stream, code := fs.OpenDir(dir, nil)
if code == fuse.ENOENT {
// The directory not existing is not an error.
return map[string]bool{}
return map[string]struct{}{}
}
if !code.Ok() {
return nil
}
result := make(map[string]bool)
result := make(map[string]struct{})
for _, e := range stream {
if e.Mode&fuse.S_IFREG != 0 {
result[e.Name] = true
result[e.Name] = struct{}{}
}
}
return result
......@@ -47,11 +47,11 @@ type dirCache struct {
lock sync.RWMutex
// If nil, you may call refresh() to schedule a new one.
names map[string]bool
names map[string]struct{}
updateRunning bool
}
func (c *dirCache) setMap(newMap map[string]bool) {
func (c *dirCache) setMap(newMap map[string]struct{}) {
c.lock.Lock()
defer c.lock.Unlock()
......@@ -101,7 +101,7 @@ func (c *dirCache) AddEntry(name string) {
return
}
c.names[name] = true
c.names[name] = struct{}{}
}
func newDirCache(fs pathfs.FileSystem, dir string, ttl time.Duration) *dirCache {
......@@ -121,5 +121,6 @@ func (c *dirCache) HasEntry(name string) (mapPresent bool, found bool) {
return false, false
}
return true, c.names[name]
_, ok := c.names[name]
return true, ok
}
......@@ -738,7 +738,7 @@ func (fs *unionFS) OpenDir(directory string, context *fuse.Context) (stream []fu
// We could try to use the cache, but we have a delay, so
// might as well get the fresh results async.
var wg sync.WaitGroup
var deletions map[string]bool
var deletions map[string]struct{}
wg.Add(1)
go func() {
......@@ -770,7 +770,7 @@ func (fs *unionFS) OpenDir(directory string, context *fuse.Context) (stream []fu
if deletions == nil {
_, code := fs.fileSystems[0].GetAttr(fs.options.DeletionDirName, context)
if code == fuse.ENOENT {
deletions = map[string]bool{}
deletions = map[string]struct{}{}
} else {
return nil, fuse.Status(syscall.EROFS)
}
......@@ -795,7 +795,7 @@ func (fs *unionFS) OpenDir(directory string, context *fuse.Context) (stream []fu
continue
}
deleted := deletions[filePathHash(filepath.Join(directory, k))]
_, deleted := deletions[filePathHash(filepath.Join(directory, k))]
if !deleted {
results[k] = v
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment