diff options
author | Jakob Unterwurzacher | 2017-09-03 13:56:11 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2017-09-03 13:59:53 +0200 |
commit | 276567eb13f8fcbea73aa6d0b40082983301ac80 (patch) | |
tree | 817ed38a0ae4aa1d644d0e480d5af1cd1fc6e8d9 /internal | |
parent | 7da0e97c8bffef7a688525f5bb6256c88743b4e2 (diff) |
fusefrontend: use DirIVCache in OpenDir()
Previously, OpenDir() did not use the cache at all, missing
an opportunity to speed up repeated directory reads.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/fusefrontend/fs_dir.go | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/internal/fusefrontend/fs_dir.go b/internal/fusefrontend/fs_dir.go index 44a4ad2..211eeea 100644 --- a/internal/fusefrontend/fs_dir.go +++ b/internal/fusefrontend/fs_dir.go @@ -260,18 +260,24 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f // Get DirIV (stays nil if PlaintextNames is used) var cachedIV []byte if !fs.args.PlaintextNames { - // Read the DirIV once and use it for all later name decryptions - cachedIV, err = nametransform.ReadDirIV(cDirAbsPath) - if err != nil { - // This can happen during normal operation when the directory has - // been deleted concurrently. But it can also mean that the - // gocryptfs.diriv is missing due to an error, so log the event - // at "info" level. - tlog.Info.Printf("OpenDir: %v", err) - return nil, fuse.ToStatus(err) + cachedIV, _ = fs.nameTransform.DirIVCache.Lookup(dirName) + if cachedIV == nil { + // Read the DirIV from disk and store it in the cache + fs.dirIVLock.RLock() + cachedIV, err = nametransform.ReadDirIV(cDirAbsPath) + if err != nil { + fs.dirIVLock.RUnlock() + // This can happen during normal operation when the directory has + // been deleted concurrently. But it can also mean that the + // gocryptfs.diriv is missing due to an error, so log the event + // at "info" level. + tlog.Info.Printf("OpenDir: %v", err) + return nil, fuse.ToStatus(err) + } + fs.nameTransform.DirIVCache.Store(dirName, cachedIV, cDirName) + fs.dirIVLock.RUnlock() } } - // Decrypted directory entries var plain []fuse.DirEntry var errorCount int |