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