nametransform: move diriv cache into it's own package
Needs some space to grow. renamed: internal/nametransform/diriv_cache.go -> internal/nametransform/dirivcache/dirivcache.go
This commit is contained in:
parent
32611ff97a
commit
5190cc09bb
|
@ -125,7 +125,7 @@ func (be *NameTransform) EncryptPathDirIV(plainPath string, rootDir string) (cip
|
|||
// Check if the DirIV is cached. This catches the case of the user iterating
|
||||
// over files in a directory pretty well.
|
||||
parentDir := filepath.Dir(plainPath)
|
||||
iv, cParentDir := be.DirIVCache.lookup(parentDir)
|
||||
iv, cParentDir := be.DirIVCache.Lookup(parentDir)
|
||||
if iv != nil {
|
||||
cBaseName := be.encryptAndHashName(baseName, iv)
|
||||
return filepath.Join(cParentDir, cBaseName), nil
|
||||
|
@ -138,7 +138,7 @@ func (be *NameTransform) EncryptPathDirIV(plainPath string, rootDir string) (cip
|
|||
// cached. Then we can skip a few items in the directory walk.
|
||||
// This catches the case of walking directories recursively.
|
||||
parentDir2 := filepath.Dir(parentDir)
|
||||
iv, cParentDir = be.DirIVCache.lookup(parentDir2)
|
||||
iv, cParentDir = be.DirIVCache.Lookup(parentDir2)
|
||||
if iv != nil {
|
||||
parentDirBase := filepath.Base(parentDir)
|
||||
cBaseName := be.encryptAndHashName(parentDirBase, iv)
|
||||
|
@ -159,6 +159,6 @@ func (be *NameTransform) EncryptPathDirIV(plainPath string, rootDir string) (cip
|
|||
}
|
||||
// Cache the final DirIV
|
||||
cParentDir = filepath.Dir(cipherPath)
|
||||
be.DirIVCache.store(parentDir, iv, cParentDir)
|
||||
be.DirIVCache.Store(parentDir, iv, cParentDir)
|
||||
return cipherPath, nil
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package nametransform
|
||||
package dirivcache
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
// Single-entry DirIV cache. Stores the directory IV and the encrypted
|
||||
// path.
|
||||
type dirIVCache struct {
|
||||
type DirIVCache struct {
|
||||
// Directory the DirIV belongs to
|
||||
dir string
|
||||
// Time the entry expires.
|
||||
|
@ -28,7 +28,7 @@ type dirIVCache struct {
|
|||
}
|
||||
|
||||
// lookup - fetch entry for "dir" from the cache
|
||||
func (c *dirIVCache) lookup(dir string) ([]byte, string) {
|
||||
func (c *DirIVCache) Lookup(dir string) ([]byte, string) {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
if c.cleared || c.dir != dir {
|
||||
|
@ -42,7 +42,7 @@ func (c *dirIVCache) lookup(dir string) ([]byte, string) {
|
|||
}
|
||||
|
||||
// store - write entry for "dir" into the cache
|
||||
func (c *dirIVCache) store(dir string, iv []byte, cDir string) {
|
||||
func (c *DirIVCache) Store(dir string, iv []byte, cDir string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.cleared = false
|
||||
|
@ -56,7 +56,7 @@ func (c *dirIVCache) store(dir string, iv []byte, cDir string) {
|
|||
// Clear ... clear the cache.
|
||||
// Exported because it is called from fusefrontend when directories are
|
||||
// renamed or deleted.
|
||||
func (c *dirIVCache) Clear() {
|
||||
func (c *DirIVCache) Clear() {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.cleared = true
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/rfjakob/eme"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/nametransform/dirivcache"
|
||||
"github.com/rfjakob/gocryptfs/internal/tlog"
|
||||
)
|
||||
|
||||
|
@ -16,7 +17,7 @@ import (
|
|||
type NameTransform struct {
|
||||
emeCipher *eme.EMECipher
|
||||
longNames bool
|
||||
DirIVCache dirIVCache
|
||||
DirIVCache dirivcache.DirIVCache
|
||||
// B64 = either base64.URLEncoding or base64.RawURLEncoding, depeding
|
||||
// on the Raw64 feature flag
|
||||
B64 *base64.Encoding
|
||||
|
|
Loading…
Reference in New Issue