Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
---
 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


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to