Commit 7d4c2306 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Implement PathFs.LastNode() using FileSystemConnector.Node().

parent 04f7c3eb
...@@ -189,8 +189,9 @@ func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []s ...@@ -189,8 +189,9 @@ func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []s
return parent, nil return parent, nil
} }
fullPath = strings.TrimLeft(filepath.Clean(fullPath), "/") sep := string(filepath.Separator)
comps := strings.Split(fullPath, "/") fullPath = strings.TrimLeft(filepath.Clean(fullPath), sep)
comps := strings.Split(fullPath, sep)
node := parent node := parent
if node.mountPoint == nil { if node.mountPoint == nil {
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
) )
...@@ -123,22 +122,7 @@ func (me *PathNodeFs) Path(node *Inode) string { ...@@ -123,22 +122,7 @@ func (me *PathNodeFs) Path(node *Inode) string {
} }
func (me *PathNodeFs) LastNode(name string) (*Inode, []string) { func (me *PathNodeFs) LastNode(name string) (*Inode, []string) {
if name == "" { return me.connector.Node(me.Root().Inode(), name)
return me.Root().Inode(), nil
}
name = filepath.Clean(name)
comps := strings.Split(name, string(filepath.Separator))
node := me.root.Inode()
for i, c := range comps {
next := node.GetChild(c)
if next == nil {
return node, comps[i:]
}
node = next
}
return node, nil
} }
func (me *PathNodeFs) FileNotify(path string, off int64, length int64) Status { func (me *PathNodeFs) FileNotify(path string, off int64, length int64) Status {
......
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