Commit 51e8ea2f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add FileSystemConnector.Node and use them for PathNodeFs notify methods.

parent 04a0abbf
...@@ -173,25 +173,34 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool) ...@@ -173,25 +173,34 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool)
return len(n.openFiles) == 0 return len(n.openFiles) == 0
} }
// Walk the file system starting from the root. Will return nil if // Finds a node within the currently known inodes, returns the last
// node not found. // known node and the remaining unknown path components. If parent is
func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*Inode, []string) { // nil, start from FUSE mountpoint.
func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string) {
if parent == nil {
parent = me.rootNode
}
if fullPath == "" { if fullPath == "" {
return me.rootNode, nil return parent, nil
} }
fullPath = strings.TrimLeft(filepath.Clean(fullPath), "/") fullPath = strings.TrimLeft(filepath.Clean(fullPath), "/")
comps := strings.Split(fullPath, "/") comps := strings.Split(fullPath, "/")
node := me.rootNode node := parent
if node.mountPoint == nil {
node.treeLock.RLock()
defer node.treeLock.RUnlock()
}
for i, component := range comps { for i, component := range comps {
if len(component) == 0 { if len(component) == 0 {
continue continue
} }
if node.mountPoint != nil { if node.mountPoint != nil {
node.mountPoint.treeLock.RLock() node.treeLock.RLock()
defer node.mountPoint.treeLock.RUnlock() defer node.treeLock.RUnlock()
} }
next := node.children[component] next := node.children[component]
...@@ -204,14 +213,6 @@ func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*Inode, []st ...@@ -204,14 +213,6 @@ func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*Inode, []st
return node, nil return node, nil
} }
func (me *FileSystemConnector) findInode(fullPath string) *Inode {
n, rest := me.findLastKnownInode(fullPath)
if len(rest) > 0 {
return nil
}
return n
}
func (me *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode { func (me *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode {
if path == "" { if path == "" {
return parent return parent
......
...@@ -146,23 +146,23 @@ func (me *PathNodeFs) LastNode(name string) (*Inode, []string) { ...@@ -146,23 +146,23 @@ func (me *PathNodeFs) LastNode(name string) (*Inode, []string) {
} }
func (me *PathNodeFs) FileNotify(path string, off int64, length int64) Status { func (me *PathNodeFs) FileNotify(path string, off int64, length int64) Status {
node := me.Node(path) node, r := me.connector.Node(me.root.Inode(), path)
if node == nil { if len(r) > 0 {
return ENOENT return ENOENT
} }
return me.connector.FileNotify(node, off, length) return me.connector.FileNotify(node, off, length)
} }
func (me *PathNodeFs) EntryNotify(dir string, name string) Status { func (me *PathNodeFs) EntryNotify(dir string, name string) Status {
node := me.Node(dir) node, rest := me.connector.Node(me.root.Inode(), dir)
if node == nil { if len(rest) > 0 {
return ENOENT return ENOENT
} }
return me.connector.EntryNotify(node, name) return me.connector.EntryNotify(node, name)
} }
func (me *PathNodeFs) Notify(path string) Status { func (me *PathNodeFs) Notify(path string) Status {
node, rest := me.LastNode(path) node, rest := me.connector.Node(me.root.Inode(), path)
if len(rest) > 0 { if len(rest) > 0 {
return me.connector.EntryNotify(node, rest[0]) return me.connector.EntryNotify(node, rest[0])
} }
...@@ -272,7 +272,7 @@ func (me *pathInode) GetPath() (path string) { ...@@ -272,7 +272,7 @@ func (me *pathInode) GetPath() (path string) {
} }
p := ReverseJoin(rev_components, "/") p := ReverseJoin(rev_components, "/")
if me.pathFs.Debug { if me.pathFs.Debug {
log.Printf("Inode %d = %q", me.Inode().nodeId, p) log.Printf("Inode %d = %q (%s)", me.Inode().nodeId, p, me.fs.String())
} }
return p return p
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment