From 6b27b6a1e71e8cd7c4910192cc31e70d3d1b652d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 6 Feb 2016 20:27:28 +0100 Subject: Move dirIVCache to its own file --- internal/nametransform/diriv_cache.go | 43 +++++++++++++++++++++++++++++++++++ internal/nametransform/names_diriv.go | 41 --------------------------------- 2 files changed, 43 insertions(+), 41 deletions(-) create mode 100644 internal/nametransform/diriv_cache.go (limited to 'internal') diff --git a/internal/nametransform/diriv_cache.go b/internal/nametransform/diriv_cache.go new file mode 100644 index 0000000..c6f2ca9 --- /dev/null +++ b/internal/nametransform/diriv_cache.go @@ -0,0 +1,43 @@ +package nametransform + +import "sync" + +// A simple one-entry DirIV cache +type dirIVCache struct { + // Invalidated? + cleared bool + // The DirIV + iv []byte + // Directory the DirIV belongs to + dir string + // Ecrypted version of "dir" + translatedDir string + // Synchronisation + lock sync.RWMutex +} + +// lookup - fetch entry for "dir" from the cache +func (c *dirIVCache) lookup(dir string) (bool, []byte, string) { + c.lock.RLock() + defer c.lock.RUnlock() + if !c.cleared && c.dir == dir { + return true, c.iv, c.translatedDir + } + return false, nil, "" +} + +// store - write entry for "dir" into the caches +func (c *dirIVCache) store(dir string, iv []byte, translatedDir string) { + c.lock.Lock() + defer c.lock.Unlock() + c.cleared = false + c.iv = iv + c.dir = dir + c.translatedDir = translatedDir +} + +func (c *dirIVCache) Clear() { + c.lock.Lock() + defer c.lock.Unlock() + c.cleared = true +} diff --git a/internal/nametransform/names_diriv.go b/internal/nametransform/names_diriv.go index 61e5bf0..94c41c8 100644 --- a/internal/nametransform/names_diriv.go +++ b/internal/nametransform/names_diriv.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" "strings" - "sync" "github.com/rfjakob/gocryptfs/internal/cryptocore" "github.com/rfjakob/gocryptfs/internal/toggledlog" @@ -20,46 +19,6 @@ const ( DirIVFilename = "gocryptfs.diriv" ) -// A simple one-entry DirIV cache -type dirIVCache struct { - // Invalidated? - cleared bool - // The DirIV - iv []byte - // Directory the DirIV belongs to - dir string - // Ecrypted version of "dir" - translatedDir string - // Synchronisation - lock sync.RWMutex -} - -// lookup - fetch entry for "dir" from the cache -func (c *dirIVCache) lookup(dir string) (bool, []byte, string) { - c.lock.RLock() - defer c.lock.RUnlock() - if !c.cleared && c.dir == dir { - return true, c.iv, c.translatedDir - } - return false, nil, "" -} - -// store - write entry for "dir" into the caches -func (c *dirIVCache) store(dir string, iv []byte, translatedDir string) { - c.lock.Lock() - defer c.lock.Unlock() - c.cleared = false - c.iv = iv - c.dir = dir - c.translatedDir = translatedDir -} - -func (c *dirIVCache) Clear() { - c.lock.Lock() - defer c.lock.Unlock() - c.cleared = true -} - // readDirIV - read the "gocryptfs.diriv" file from "dir" (absolute ciphertext path) func (be *NameTransform) ReadDirIV(dir string) (iv []byte, readErr error) { ivfile := filepath.Join(dir, DirIVFilename) -- cgit v1.2.3