From 35bcc2dca2dc928e3b7c31e34d785b7a42c06722 Mon Sep 17 00:00:00 2001
From: Jakob Unterwurzacher
Date: Thu, 22 Sep 2016 19:54:37 +0200
Subject: reverse: transform long names in OpenDir

---
 internal/fusefrontend_reverse/rfs.go | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

(limited to 'internal/fusefrontend_reverse')

diff --git a/internal/fusefrontend_reverse/rfs.go b/internal/fusefrontend_reverse/rfs.go
index 4f516fd..9fac591 100644
--- a/internal/fusefrontend_reverse/rfs.go
+++ b/internal/fusefrontend_reverse/rfs.go
@@ -218,19 +218,27 @@ func (rfs *reverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.
 	if entries == nil {
 		return nil, status
 	}
+	// Virtual gocryptfs.diriv file
+	dirIVEntry := fuse.DirEntry{syscall.S_IFREG | 0400, nametransform.DirIVFilename}
+	virtualFiles := []fuse.DirEntry{dirIVEntry}
 	// Encrypt names
 	dirIV := deriveDirIV(cipherPath)
 	for i := range entries {
+		var cName string
 		// ".gocryptfs.reverse.conf" in the root directory is mapped to "gocryptfs.conf"
 		if cipherPath == "" && entries[i].Name == configfile.ConfReverseName {
-			entries[i].Name = configfile.ConfDefaultName
+			cName = configfile.ConfDefaultName
 		} else {
-			entries[i].Name = rfs.nameTransform.EncryptName(entries[i].Name, dirIV)
+			cName = rfs.nameTransform.EncryptName(entries[i].Name, dirIV)
+			if len(cName) > syscall.NAME_MAX {
+				cName = nametransform.HashLongName(cName)
+				dotNameFile := fuse.DirEntry{syscall.S_IFREG | 0600, cName + nametransform.LongNameSuffix}
+				virtualFiles = append(virtualFiles, dotNameFile)
+			}
 		}
+		entries[i].Name = cName
 	}
-	// Add virtual gocryptfs.diriv
-	entries = append(entries, fuse.DirEntry{syscall.S_IFREG | 0400, nametransform.DirIVFilename})
-
+	entries = append(entries, virtualFiles...)
 	return entries, fuse.OK
 }
 
-- 
cgit v1.2.3