mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] ls: allow to list a symlink ending with '/' as a dir
Date: Fri,  3 Mar 2017 16:31:36 +0100	[thread overview]
Message-ID: <1488555097-21189-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20170303152759.GF4120@mail.ovh.net>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2017-03-03 15:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 15:27 [PATCH 0/2] efivarfs: rework the filesystem to make it human readable Jean-Christophe PLAGNIOL-VILLARD
2017-03-03 15:31 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2017-03-03 15:31   ` [PATCH 2/2] " Jean-Christophe PLAGNIOL-VILLARD
2017-03-09 14:38 ` [PATCH 0/2] " Jean-Christophe PLAGNIOL-VILLARD
2017-03-13  7:24   ` Sascha Hauer
2017-03-13  8:20     ` Michael Olbrich
2017-03-13 10:19       ` Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1488555097-21189-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox