aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/root_node.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-08-15 17:31:25 +0200
committerJakob Unterwurzacher2020-08-15 17:31:45 +0200
commit94e8fc12ea5756a130e7ac9ed67ddd519b5f3a22 (patch)
tree44186807f71db8c555af23f8969f8f1456c955f9 /internal/fusefrontend_reverse/root_node.go
parent15b0b4a5fd268b421ddc347e4417b2538a540922 (diff)
v2api/reverse: finish -exclude
Tests pass now.
Diffstat (limited to 'internal/fusefrontend_reverse/root_node.go')
-rw-r--r--internal/fusefrontend_reverse/root_node.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/internal/fusefrontend_reverse/root_node.go b/internal/fusefrontend_reverse/root_node.go
index 4346306..b7a259a 100644
--- a/internal/fusefrontend_reverse/root_node.go
+++ b/internal/fusefrontend_reverse/root_node.go
@@ -2,12 +2,16 @@ package fusefrontend_reverse
import (
"log"
+ "path/filepath"
"strings"
"syscall"
+ "github.com/rfjakob/gocryptfs/internal/tlog"
+
"golang.org/x/sys/unix"
"github.com/hanwen/go-fuse/v2/fs"
+ "github.com/hanwen/go-fuse/v2/fuse"
"github.com/rfjakob/gocryptfs/internal/contentenc"
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
@@ -28,7 +32,7 @@ type RootNode struct {
// Content encryption helper
contentEnc *contentenc.ContentEnc
// Tests whether a path is excluded (hidden) from the user. Used by -exclude.
- excluder *ignore.GitIgnore
+ excluder ignore.IgnoreParser
// inoMap translates inode numbers from different devices to unique inode
// numbers.
inoMap *inomap.InoMap
@@ -38,17 +42,23 @@ type RootNode struct {
// In this case (reverse mode) the backing directory is plain-text and
// ReverseFS provides an encrypted view.
func NewRootNode(args fusefrontend.Args, c *contentenc.ContentEnc, n nametransform.NameTransformer) *RootNode {
- return &RootNode{
+ rn := &RootNode{
args: args,
nameTransform: n,
contentEnc: c,
inoMap: inomap.New(),
- excluder: prepareExcluder(args),
}
+ if len(args.Exclude) > 0 || len(args.ExcludeWildcard) > 0 || len(args.ExcludeFrom) > 0 {
+ rn.excluder = prepareExcluder(args)
+ }
+ return rn
}
// You can pass either gocryptfs.longname.XYZ.name or gocryptfs.longname.XYZ.
func (rn *RootNode) findLongnameParent(fd int, diriv []byte, longname string) (pName string, cFullName string, errno syscall.Errno) {
+ defer func() {
+ tlog.Debug.Printf("findLongnameParent: %d %x %q -> %q %q %d\n", fd, diriv, longname, pName, cFullName, errno)
+ }()
if strings.HasSuffix(longname, nametransform.LongNameSuffix) {
longname = nametransform.RemoveLongNameSuffix(longname)
}
@@ -84,3 +94,24 @@ func (rn *RootNode) findLongnameParent(fd int, diriv []byte, longname string) (p
func (rn *RootNode) isExcludedPlain(pPath string) bool {
return rn.excluder != nil && rn.excluder.MatchesPath(pPath)
}
+
+// excludeDirEntries filters out directory entries that are "-exclude"d.
+// pDir is the relative plaintext path to the directory these entries are
+// from. The entries should be plaintext files.
+func (rn *RootNode) excludeDirEntries(d *dirfdPlus, entries []fuse.DirEntry) (filtered []fuse.DirEntry) {
+ if rn.excluder == nil {
+ return entries
+ }
+ filtered = make([]fuse.DirEntry, 0, len(entries))
+ for _, entry := range entries {
+ // filepath.Join handles the case of pDir="" correctly:
+ // Join("", "foo") -> "foo". This does not: pDir + "/" + name"
+ p := filepath.Join(d.pPath, entry.Name)
+ if rn.isExcludedPlain(p) {
+ // Skip file
+ continue
+ }
+ filtered = append(filtered, entry)
+ }
+ return filtered
+}