Commit 1e311fd7 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add FilesystemConnector.Notify() which chooses between entry and inode

notify automatically.
parent 130d5381
...@@ -470,16 +470,16 @@ func (me *FileSystemConnector) unlinkUpdate(parent *inode, name string) { ...@@ -470,16 +470,16 @@ func (me *FileSystemConnector) unlinkUpdate(parent *inode, name string) {
// Walk the file system starting from the root. Will return nil if // Walk the file system starting from the root. Will return nil if
// node not found. // node not found.
func (me *FileSystemConnector) findInode(fullPath string) *inode { func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*inode, []string) {
if fullPath == "" { if fullPath == "" {
return me.rootNode return me.rootNode, 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 := me.rootNode
for _, component := range comps { for i, component := range comps {
if len(component) == 0 { if len(component) == 0 {
continue continue
} }
...@@ -489,12 +489,22 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode { ...@@ -489,12 +489,22 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode {
defer node.mountPoint.treeLock.RUnlock() defer node.mountPoint.treeLock.RUnlock()
} }
node = node.Children[component] next := node.Children[component]
if node == nil { if next == nil {
return nil return node, comps[i:]
}
node = next
} }
return node, nil
}
func (me *FileSystemConnector) findInode(fullPath string) *inode {
n, rest := me.findLastKnownInode(fullPath)
if len(rest) > 0 {
return nil
} }
return node return n
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
...@@ -703,3 +713,16 @@ func (me *FileSystemConnector) EntryNotify(dir string, name string) Status { ...@@ -703,3 +713,16 @@ func (me *FileSystemConnector) EntryNotify(dir string, name string) Status {
return me.fsInit.EntryNotify(node.NodeId, name) return me.fsInit.EntryNotify(node.NodeId, name)
} }
func (me *FileSystemConnector) Notify(path string) Status {
node, rest := me.findLastKnownInode(path)
if len(rest) > 0 {
return me.fsInit.EntryNotify(node.NodeId, rest[0])
}
out := NotifyInvalInodeOut{
Ino: node.NodeId,
}
return me.fsInit.InodeNotify(&out)
}
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