aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/fusefrontend/fs_dir.go26
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