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)
return len(n.openFiles) == 0
}
// Walk the file system starting from the root. Will return nil if
// node not found.
func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*Inode, []string) {
// Finds a node within the currently known inodes, returns the last
// known node and the remaining unknown path components. If parent is
// nil, start from FUSE mountpoint.
func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string) {
if parent == nil {
parent = me.rootNode
}
if fullPath == "" {
return me.rootNode, nil
return parent, nil
}
fullPath = strings.TrimLeft(filepath.Clean(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 {
if len(component) == 0 {
continue
}
if node.mountPoint != nil {
node.mountPoint.treeLock.RLock()
defer node.mountPoint.treeLock.RUnlock()
node.treeLock.RLock()
defer node.treeLock.RUnlock()
}
next := node.children[component]
......@@ -204,14 +213,6 @@ func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*Inode, []st
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 {
if path == "" {
return parent
......
......@@ -146,23 +146,23 @@ func (me *PathNodeFs) LastNode(name string) (*Inode, []string) {
}
func (me *PathNodeFs) FileNotify(path string, off int64, length int64) Status {
node := me.Node(path)
if node == nil {
node, r := me.connector.Node(me.root.Inode(), path)
if len(r) > 0 {
return ENOENT
}
return me.connector.FileNotify(node, off, length)
}
func (me *PathNodeFs) EntryNotify(dir string, name string) Status {
node := me.Node(dir)
if node == nil {
node, rest := me.connector.Node(me.root.Inode(), dir)
if len(rest) > 0 {
return ENOENT
}
return me.connector.EntryNotify(node, name)
}
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 {
return me.connector.EntryNotify(node, rest[0])
}
......@@ -272,7 +272,7 @@ func (me *pathInode) GetPath() (path string) {
}
p := ReverseJoin(rev_components, "/")
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
......
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