mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/4] ls: Fix showing links to directories
Date: Thu, 11 May 2017 11:11:01 +0200	[thread overview]
Message-ID: <20170511091101.5821-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170511091101.5821-1-s.hauer@pengutronix.de>

With links to directories we have to do some adjustments in the
printout. In ls_one we have to use lstat() because we want to
show informations about the file or link. When determing if it's
a file or directory that we show we have to use stat() instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/ls.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/commands/ls.c b/commands/ls.c
index 331a4d2015..771477b6e0 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -26,15 +26,21 @@
 #include <getopt.h>
 #include <stringlist.h>
 
-static void ls_one(const char *path, const char* fullname, struct stat *s)
+static void ls_one(const char *path, const char* fullname)
 {
 	char modestr[11];
 	unsigned int namelen = strlen(path);
+	struct stat s;
+	int ret;
+
+	ret = lstat(fullname, &s);
+	if (ret)
+		return;
 
-	mkmodestr(s->st_mode, modestr);
-	printf("%s %14llu %*.*s", modestr, s->st_size, namelen, namelen, path);
+	mkmodestr(s.st_mode, modestr);
+	printf("%s %14llu %*.*s", modestr, s.st_size, namelen, namelen, path);
 
-	if (S_ISLNK(s->st_mode)) {
+	if (S_ISLNK(s.st_mode)) {
 		char realname[PATH_MAX];
 
 		memset(realname, 0, PATH_MAX);
@@ -58,14 +64,14 @@ int ls(const char *path, ulong flags)
 
 	string_list_init(&sl);
 
-	if (lstat(path, &s))
+	if (stat(path, &s))
 		return -errno;
 
 	if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
 		printf("%s:\n", path);
 
 	if (!(s.st_mode & S_IFDIR)) {
-		ls_one(path, path, &s);
+		ls_one(path, path);
 		return 0;
 	}
 
@@ -89,7 +95,7 @@ int ls(const char *path, ulong flags)
 				continue;
 			}
 
-			ls_one(entry->str, tmp, &s);
+			ls_one(entry->str, tmp);
 		}
 	}
 
@@ -162,7 +168,7 @@ static int do_ls(int argc, char *argv[])
 
 	/* first pass: all files */
 	while (o < argc) {
-		ret = lstat(argv[o], &s);
+		ret = stat(argv[o], &s);
 		if (ret) {
 			printf("%s: %s: %s\n", argv[0],
 					argv[o], errno_str());
@@ -175,7 +181,7 @@ static int do_ls(int argc, char *argv[])
 			if (flags & LS_COLUMN)
 				string_list_add_sorted(&sl, argv[o]);
 			else
-				ls_one(argv[o], argv[o], &s);
+				ls_one(argv[o], argv[o]);
 		}
 
 		o++;
@@ -190,7 +196,7 @@ static int do_ls(int argc, char *argv[])
 
 	/* second pass: directories */
 	while (o < argc) {
-		ret = lstat(argv[o], &s);
+		ret = stat(argv[o], &s);
 		if (ret) {
 			o++;
 			exitcode = COMMAND_ERROR;
-- 
2.11.0


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

      parent reply	other threads:[~2017-05-11  9:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-11  9:10 Implement symlinks " Sascha Hauer
2017-05-11  9:10 ` [PATCH 1/4] errno: Include string for ELOOP Sascha Hauer
2017-05-11  9:10 ` [PATCH 2/4] fs: drop path_check_prereq() Sascha Hauer
2017-05-11  9:11 ` [PATCH 3/4] fs: Implement links to directories Sascha Hauer
2017-05-11 19:34   ` Sascha Hauer
2017-05-11  9:11 ` Sascha Hauer [this message]

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=20170511091101.5821-5-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --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