From edd63a422b33fc84f3add3bb3e8bf893d5cba96e Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sat, 28 Nov 2020 02:39:58 -0600 Subject: [PATCH] Support for ../ in directory paths --- file.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/file.go b/file.go index e58d059..96fdb23 100644 --- a/file.go +++ b/file.go @@ -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:], "/"))