ls: w/o -l follow symlinks to dirs for commandline args

This commit is contained in:
Denis Vlasenko 2007-02-28 23:14:06 +00:00
parent 4c7e5b6c76
commit 2110aa9ece

View File

@ -156,13 +156,13 @@ enum {
static int status = EXIT_SUCCESS; static int status = EXIT_SUCCESS;
static struct dnode *my_stat(char *fullname, char *name) static struct dnode *my_stat(char *fullname, char *name, int force_follow)
{ {
struct stat dstat; struct stat dstat;
struct dnode *cur; struct dnode *cur;
USE_SELINUX(security_context_t sid = NULL;) USE_SELINUX(security_context_t sid = NULL;)
if (all_fmt & FOLLOW_LINKS) { if ((all_fmt & FOLLOW_LINKS) || force_follow) {
#if ENABLE_SELINUX #if ENABLE_SELINUX
if (is_selinux_enabled()) { if (is_selinux_enabled()) {
getfilecon(fullname, &sid); getfilecon(fullname, &sid);
@ -176,7 +176,7 @@ static struct dnode *my_stat(char *fullname, char *name)
} else { } else {
#if ENABLE_SELINUX #if ENABLE_SELINUX
if (is_selinux_enabled()) { if (is_selinux_enabled()) {
lgetfilecon(fullname,&sid); lgetfilecon(fullname, &sid);
} }
#endif #endif
if (lstat(fullname, &dstat)) { if (lstat(fullname, &dstat)) {
@ -510,7 +510,7 @@ static struct dnode **list_dir(const char *path)
continue; continue;
} }
fullname = concat_path_file(path, entry->d_name); fullname = concat_path_file(path, entry->d_name);
cur = my_stat(fullname, strrchr(fullname, '/') + 1); cur = my_stat(fullname, strrchr(fullname, '/') + 1, 0);
if (!cur) { if (!cur) {
free(fullname); free(fullname);
continue; continue;
@ -837,8 +837,9 @@ int ls_main(int argc, char **argv)
all_fmt &= ~TIME_MASK; all_fmt &= ~TIME_MASK;
if (flags & LIST_CONTEXT) if (flags & LIST_CONTEXT)
all_fmt |= STYLE_SINGLE; all_fmt |= STYLE_SINGLE;
if (LS_DISP_HR && opt == 'l') /* huh?? opt cannot be 'l' */
all_fmt &= ~LS_DISP_HR; //if (LS_DISP_HR && opt == 'l')
// all_fmt &= ~LS_DISP_HR;
all_fmt |= flags; all_fmt |= flags;
} }
} }
@ -904,7 +905,8 @@ int ls_main(int argc, char **argv)
/* stuff the command line file names into a dnode array */ /* stuff the command line file names into a dnode array */
dn = NULL; dn = NULL;
for (oi = 0; oi < ac; oi++) { for (oi = 0; oi < ac; oi++) {
cur = my_stat(av[oi], av[oi]); /* ls w/o -l follows links on command line */
cur = my_stat(av[oi], av[oi], !(all_fmt & STYLE_LONG));
if (!cur) if (!cur)
continue; continue;
cur->allocated = 0; cur->allocated = 0;