diff --git a/nav.go b/nav.go index f9d6452..04dabfc 100644 --- a/nav.go +++ b/nav.go @@ -101,12 +101,29 @@ func readdir(path string) ([]*file, error) { // i.e. directories, filenames without extensions ext := filepath.Ext(fpath) + dirCount := -1 + if lstat.IsDir() && gOpts.dircounts { + d, err := os.Open(fpath) + if err != nil { + dirCount = -2 + } + + names, err := d.Readdirnames(1000) + d.Close() + + if names == nil && err != io.EOF { + dirCount = -2 + } else { + dirCount = len(names) + } + } + files = append(files, &file{ FileInfo: lstat, linkState: linkState, linkTarget: linkTarget, path: fpath, - dirCount: -1, + dirCount: dirCount, dirSize: -1, accessTime: at, changeTime: ct, diff --git a/ui.go b/ui.go index f147043..8e2b3aa 100644 --- a/ui.go +++ b/ui.go @@ -3,7 +3,6 @@ package main import ( "bytes" "fmt" - "io" "log" "os" "path/filepath" @@ -287,8 +286,6 @@ func infotimefmt(t time.Time) string { func fileInfo(f *file, d *dir) string { var info string - path := filepath.Join(d.path, f.Name()) - for _, s := range gOpts.info { switch s { case "size": @@ -303,23 +300,9 @@ func fileInfo(f *file, d *dir) string { continue } - if f.dirCount == -1 { - d, err := os.Open(path) - if err != nil { - f.dirCount = -2 - } - - names, err := d.Readdirnames(1000) - d.Close() - - if names == nil && err != io.EOF { - f.dirCount = -2 - } else { - f.dirCount = len(names) - } - } - switch { + case f.dirCount < -1: + info = fmt.Sprintf("%s !", info) case f.dirCount < 0: info = fmt.Sprintf("%s ?", info) case f.dirCount < 1000: