Support for ../ in directory paths

This commit is contained in:
Caleb Gardner
2020-11-28 02:39:58 -06:00
parent 938fd30d73
commit edd63a422b
+9
View File
@@ -118,10 +118,19 @@ func (f *File) GetFileAtPath(path string) *File {
path = strings.TrimPrefix(path, "./")
}
split := strings.Split(path, "/")
if split[0] == ".." && f.Name == "" {
return nil
} else if split[0] == ".." {
if f.Parent != nil {
return f.Parent.GetFileAtPath(strings.Join(split[1:], "/"))
}
return nil
}
children, err := f.GetChildren()
if err != nil {
return nil
}
for _, child := range children {
if child.Name == split[0] {
return child.GetFileAtPath(strings.Join(split[1:], "/"))