From 992cac834e1c616c4e8ac5f45da8f09d14ff7836 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Thu, 13 Oct 2022 11:30:34 -0400 Subject: [PATCH] fix: symlink directory follows directory --- file/file.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/file/file.go b/file/file.go index d1db75a..eab34f0 100644 --- a/file/file.go +++ b/file/file.go @@ -145,15 +145,36 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if len(m.files) == 0 { break } - if !m.files[m.selected].IsDir() { + + f := m.files[m.selected] + info, err := f.Info() + if err != nil { + break + } + isSymlink := info.Mode()&fs.ModeSymlink != 0 + isDir := f.IsDir() + + if isSymlink { + symlinkPath, _ := filepath.EvalSymlinks(filepath.Join(m.path, f.Name())) + info, err := os.Stat(symlinkPath) + if err != nil { + break + } + if info.IsDir() { + isDir = true + } + } + + if !isDir { if msg.String() == "enter" { - m.path = filepath.Join(m.path, m.files[m.selected].Name()) + m.path = filepath.Join(m.path, f.Name()) m.quitting = true return m, tea.Quit } break } - m.path = filepath.Join(m.path, m.files[m.selected].Name()) + + m.path = filepath.Join(m.path, f.Name()) m.pushView() m.selected = 0 m.min = 0