Add a -I option to disable the automatic -A flag for the super-user.

PR:		bin/86710
Submitted by:	Marcus Alves Grando
MFC after:	3 days
This commit is contained in:
Maxime Henrion 2005-11-10 00:02:32 +00:00
parent 6fe8148234
commit 7b7d153b21
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=152256
2 changed files with 25 additions and 9 deletions

View file

@ -40,7 +40,7 @@
.Nd list directory contents .Nd list directory contents
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl ABCFGHLPRSTWZabcdfghiklmnopqrstuwx1 .Op Fl ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1
.Op Ar .Op Ar
.Sh DESCRIPTION .Sh DESCRIPTION
For each operand that names a For each operand that names a
@ -73,6 +73,8 @@ List all entries except for
and and
.Pa .. . .Pa .. .
Always set for the super-user. Always set for the super-user.
.Fl I
cancel this option.
.It Fl B .It Fl B
Force printing of non-printable characters (as defined by Force printing of non-printable characters (as defined by
.Xr ctype 3 .Xr ctype 3
@ -117,6 +119,12 @@ none of the
or or
.Fl l .Fl l
options are specified. options are specified.
.It Fl I
This option cancels the
.Fl A
option. Usually used by super-user when
.Fl A
is not necessary.
.It Fl L .It Fl L
If argument is a symbolic link, list the file or directory the link references If argument is a symbolic link, list the file or directory the link references
rather than the link itself. rather than the link itself.

View file

@ -110,6 +110,8 @@ int termwidth = 80; /* default terminal width */
static int f_kblocks; /* print size in kilobytes */ static int f_kblocks; /* print size in kilobytes */
static int f_listdir; /* list actual directory, not contents */ static int f_listdir; /* list actual directory, not contents */
static int f_listdot; /* list files beginning with . */ static int f_listdot; /* list files beginning with . */
static int f_nolistdot; /* don't list files beginning with . */
static int f_forcelistdot; /* force list files beginning with . */
int f_longform; /* long listing format */ int f_longform; /* long listing format */
int f_nonprint; /* show unprintables as ? */ int f_nonprint; /* show unprintables as ? */
static int f_nosort; /* don't sort output */ static int f_nosort; /* don't sort output */
@ -175,13 +177,9 @@ main(int argc, char *argv[])
termwidth = atoi(p); termwidth = atoi(p);
} }
/* Root is -A automatically. */
if (!getuid())
f_listdot = 1;
fts_options = FTS_PHYSICAL; fts_options = FTS_PHYSICAL;
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
"1ABCFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) { "1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
switch (ch) { switch (ch) {
/* /*
* The -1, -C, -x and -l options all override each other so * The -1, -C, -x and -l options all override each other so
@ -243,10 +241,14 @@ main(int argc, char *argv[])
break; break;
case 'a': case 'a':
fts_options |= FTS_SEEDOT; fts_options |= FTS_SEEDOT;
/* FALLTHROUGH */ f_forcelistdot = 1;
break;
case 'A': case 'A':
f_listdot = 1; f_listdot = 1;
break; break;
case 'I':
f_nolistdot = 1;
break;
/* The -d option turns off the -R option. */ /* The -d option turns off the -R option. */
case 'd': case 'd':
f_listdir = 1; f_listdir = 1;
@ -326,6 +328,10 @@ main(int argc, char *argv[])
argc -= optind; argc -= optind;
argv += optind; argv += optind;
/* Root is -A automatically. */
if (!getuid() && !f_nolistdot)
f_listdot = 1;
/* Enabling of colours is conditional on the environment. */ /* Enabling of colours is conditional on the environment. */
if (getenv("CLICOLOR") && if (getenv("CLICOLOR") &&
(isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE"))) (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
@ -490,7 +496,8 @@ traverse(int argc, char *argv[], int options)
break; break;
case FTS_D: case FTS_D:
if (p->fts_level != FTS_ROOTLEVEL && if (p->fts_level != FTS_ROOTLEVEL &&
p->fts_name[0] == '.' && !f_listdot) p->fts_name[0] == '.' && ((!f_listdot ||
f_nolistdot) && !f_forcelistdot))
break; break;
/* /*
@ -650,7 +657,8 @@ display(const FTSENT *p, FTSENT *list, int options)
} }
} else { } else {
/* Only display dot file if -a/-A set. */ /* Only display dot file if -a/-A set. */
if (cur->fts_name[0] == '.' && !f_listdot) { if (cur->fts_name[0] == '.' && ((!f_listdot ||
f_nolistdot) && !f_forcelistdot)) {
cur->fts_number = NO_PRINT; cur->fts_number = NO_PRINT;
continue; continue;
} }