diff options
author | Jakob Unterwurzacher | 2017-08-06 21:59:15 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2017-08-06 21:59:15 +0200 |
commit | 5190cc09bbc8afca75986dbb14f09e62eda33b61 (patch) | |
tree | 37e5d9fc3febd063e9c09dc44dfbdaefd300a9c3 /internal/nametransform | |
parent | 32611ff97afacb6525015ed322645e12bd296380 (diff) |
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
Diffstat (limited to 'internal/nametransform')
-rw-r--r-- | internal/nametransform/diriv.go | 6 | ||||
-rw-r--r-- | internal/nametransform/dirivcache/dirivcache.go (renamed from internal/nametransform/diriv_cache.go) | 10 | ||||
-rw-r--r-- | internal/nametransform/names.go | 3 |
3 files changed, 10 insertions, 9 deletions
diff --git a/internal/nametransform/diriv.go b/internal/nametransform/diriv.go index 5fca1ef..6746f04 100644 --- a/internal/nametransform/diriv.go +++ b/internal/nametransform/diriv.go @@ -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 } diff --git a/internal/nametransform/diriv_cache.go b/internal/nametransform/dirivcache/dirivcache.go index 82c5bd3..890ebac 100644 --- a/internal/nametransform/diriv_cache.go +++ b/internal/nametransform/dirivcache/dirivcache.go @@ -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 diff --git a/internal/nametransform/names.go b/internal/nametransform/names.go index 3447583..94fa453 100644 --- a/internal/nametransform/names.go +++ b/internal/nametransform/names.go @@ -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 |