From 75ec94a87a52a7230c9b7d9b3e150a0da2725e58 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 6 Aug 2017 23:12:27 +0200 Subject: nametransform: add Dir() function Dir is like filepath.Dir but returns "" instead of ".". This was already implemented in fusefrontend_reverse as saneDir(). We will need it in nametransform for the improved diriv caching. --- internal/fusefrontend_reverse/rpath.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'internal/fusefrontend_reverse/rpath.go') diff --git a/internal/fusefrontend_reverse/rpath.go b/internal/fusefrontend_reverse/rpath.go index 6f6895a..fa7680f 100644 --- a/internal/fusefrontend_reverse/rpath.go +++ b/internal/fusefrontend_reverse/rpath.go @@ -11,15 +11,6 @@ import ( "github.com/rfjakob/gocryptfs/internal/tlog" ) -// saneDir is like filepath.Dir but returns "" instead of "." -func saneDir(path string) string { - d := filepath.Dir(path) - if d == "." { - return "" - } - return d -} - // abs basically returns storage dir + "/" + relPath. // It takes an error parameter so it can directly wrap decryptPath like this: // a, err := rfs.abs(rfs.decryptPath(relPath)) @@ -71,7 +62,7 @@ func (rfs *ReverseFS) decryptPath(relPath string) (string, error) { return relPath, nil } // Check if the parent dir is in the cache - cDir := saneDir(relPath) + cDir := nametransform.Dir(relPath) dirIV, pDir := rPathCache.lookup(cDir) if dirIV != nil { cName := filepath.Base(relPath) @@ -95,6 +86,6 @@ func (rfs *ReverseFS) decryptPath(relPath string) (string, error) { transformedParts = append(transformedParts, transformedPart) } pRelPath := filepath.Join(transformedParts...) - rPathCache.store(cDir, dirIV, saneDir(pRelPath)) + rPathCache.store(cDir, dirIV, nametransform.Dir(pRelPath)) return pRelPath, nil } -- cgit v1.2.3