[PATCH 1/2] ls: allow to list a symlink ending with '/' as a dir

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Mar 3 07:31:36 PST 2017


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 commands/ls.c | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/commands/ls.c b/commands/ls.c
index 331a4d201..3bd5e3ff8 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -64,6 +64,16 @@ int ls(const char *path, ulong flags)
 	if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
 		printf("%s:\n", path);
 
+	if (S_ISLNK(s.st_mode)) {
+		int len = strlen(path);
+			
+		if (path[len - 1] != '/') {
+			ls_one(path, path, &s);
+			return 0;
+		}
+		s.st_mode |= S_IFDIR;
+	}
+
 	if (!(s.st_mode & S_IFDIR)) {
 		ls_one(path, path, &s);
 		return 0;
@@ -171,13 +181,25 @@ static int do_ls(int argc, char *argv[])
 			continue;
 		}
 
-		if (!(s.st_mode & S_IFDIR)) {
-			if (flags & LS_COLUMN)
-				string_list_add_sorted(&sl, argv[o]);
-			else
-				ls_one(argv[o], argv[o], &s);
+		if (s.st_mode & S_IFDIR) {
+			o++;
+			continue;
 		}
 
+		if (s.st_mode & S_IFLNK) {
+			int len = strlen(argv[o]);
+			
+			if (argv[o][len - 1] == '/') {
+			    o++;
+			    continue;
+			}
+		}
+
+		if (flags & LS_COLUMN)
+			string_list_add_sorted(&sl, argv[o]);
+		else
+			ls_one(argv[o], argv[o], &s);
+
 		o++;
 	}
 
@@ -197,7 +219,14 @@ static int do_ls(int argc, char *argv[])
 			continue;
 		}
 
-		if (s.st_mode & S_IFDIR) {
+		if (s.st_mode & S_IFDIR || s.st_mode & S_IFLNK) {
+			int len = strlen(argv[o]);
+			
+			if (s.st_mode & S_IFLNK && argv[o][len - 1] != '/') {
+				o++;
+				continue;
+			}
+
 			ret = ls(argv[o], flags);
 			if (ret) {
 				perror("ls");
-- 
2.11.0




More information about the barebox mailing list