From 6aa1e5d8a566578fee2ba4a54ad4d9a7d564f114 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch
Date: Wed, 24 Oct 2018 13:07:14 +0200 Subject: Show symlink targets Rudimentary, needs a refactor. --- sdn.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sdn.cpp b/sdn.cpp index 9a1f5c8..10c6361 100644 --- a/sdn.cpp +++ b/sdn.cpp @@ -490,7 +490,23 @@ fun reload () { // http://lkml.iu.edu/hypermail//linux/kernel/0804.3/1616.html struct stat sb = {}; lstat (f->d_name, &sb); - g.entries.push_back ({ f->d_name, sb, make_row (f->d_name, sb) }); + + auto row = make_row (f->d_name, sb); + if (S_ISLNK (sb.st_mode)) { + char buf[PATH_MAX] = {}; + auto len = readlink (f->d_name, buf, sizeof buf); + if (len < 0 || size_t (len) >= sizeof buf) { + buf[0] = '?'; + buf[1] = 0; + } + + struct stat sbt = {}; + lstat (buf, &sbt); + + row.cols[row::FILENAME].append (apply_attrs (to_wide (" -> "), 0)) + .append (apply_attrs (to_wide (buf), ls_format (buf, sbt))); + } + g.entries.push_back ({ f->d_name, sb, row }); } closedir (dir); sort (begin (g.entries), end (g.entries)); -- cgit v1.2.3-70-g09d2