fix(file-manager): browse symlinked directories and expand home
Symlinked directories were listed as files, so Enter opened them in the editor instead of browsing them. Mappings and the remote control API reach the panel without a shell, so --start-dir now expands a leading ~ itself. Add the missing Python integration tests for the result handler.
This commit is contained in:
4 files changed
+195
-3
No files matched your search
@@ -80,7 +80,17 @@ func read_dir(dir string, show_hidden bool, sort_by string) ([]Entry, error) {
|
||||
continue
|
||||
}
|
||||
e := Entry{Name: name, IsDir: item.IsDir()}
|
||||
if info, ierr := item.Info(); ierr == nil {
|
||||
info, ierr := item.Info()
|
||||
if item.Type()&os.ModeSymlink != 0 {
|
||||
// A symlink is reported as its own type, so a link to a directory
|
||||
// would be opened in the editor instead of being browsed. Follow
|
||||
// it to classify the entry; broken links stay plain entries.
|
||||
if target, terr := os.Stat(filepath.Join(dir, name)); terr == nil {
|
||||
info, ierr = target, nil
|
||||
e.IsDir = target.IsDir()
|
||||
}
|
||||
}
|
||||
if ierr == nil {
|
||||
e.ModTime = info.ModTime().Unix()
|
||||
e.Size = info.Size()
|
||||
}
|
||||
@@ -90,6 +100,23 @@ func read_dir(dir string, show_hidden bool, sort_by string) ([]Entry, error) {
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
// expand_home expands a leading ~ so that a directory given in a mapping or by
|
||||
// the remote control API, where no shell expands it, names the same directory
|
||||
// as it would on the command line.
|
||||
func expand_home(path string) (string, error) {
|
||||
if path != "~" && !strings.HasPrefix(path, "~/") {
|
||||
return path, nil
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if path == "~" {
|
||||
return home, nil
|
||||
}
|
||||
return filepath.Join(home, path[2:]), nil
|
||||
}
|
||||
|
||||
func entry_path(dir, name string) string {
|
||||
return filepath.Join(dir, name)
|
||||
}
|
||||
@@ -169,6 +196,10 @@ func resolve_start_dir(candidate string) (string, error) {
|
||||
}
|
||||
candidate = cwd
|
||||
}
|
||||
candidate, err := expand_home(candidate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
abs, err := filepath.Abs(candidate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in new issue
Block a user