If we are asked to print the total number of blocks, do so even if we
have no entries to print (either due to an empty directory or an error). This makes the -l and -s options more consistent, like Solaris and (Debian) Linux. To make this happen, tweak two optimizations on the second call to display(): - Don't skip display() altogether, even if list == NULL. - Don't skip the call to the printfn in display() if we need to print the total. PR: 45723
This commit is contained in:
parent
e79220be15
commit
7a9a1abd40
26
bin/ls/ls.c
26
bin/ls/ls.c
@ -452,7 +452,13 @@ traverse(int argc, char *argv[], int options)
|
|||||||
fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
|
fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
|
||||||
err(1, "fts_open");
|
err(1, "fts_open");
|
||||||
|
|
||||||
display(NULL, fts_children(ftsp, 0), options);
|
/*
|
||||||
|
* We ignore errors from fts_children here since they will be
|
||||||
|
* replicated and signalled on the next call to fts_read() below.
|
||||||
|
*/
|
||||||
|
chp = fts_children(ftsp, 0);
|
||||||
|
if (chp != NULL)
|
||||||
|
display(NULL, chp, options);
|
||||||
if (f_listdir)
|
if (f_listdir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -533,16 +539,6 @@ display(const FTSENT *p, FTSENT *list, int options)
|
|||||||
char ngroup[STRBUF_SIZEOF(uid_t) + 1];
|
char ngroup[STRBUF_SIZEOF(uid_t) + 1];
|
||||||
char nuser[STRBUF_SIZEOF(gid_t) + 1];
|
char nuser[STRBUF_SIZEOF(gid_t) + 1];
|
||||||
|
|
||||||
/*
|
|
||||||
* If list is NULL there are two possibilities: that the parent
|
|
||||||
* directory p has no children, or that fts_children() returned an
|
|
||||||
* error. We ignore the error case since it will be replicated
|
|
||||||
* on the next call to fts_read() on the post-order visit to the
|
|
||||||
* directory p, and will be signaled in traverse().
|
|
||||||
*/
|
|
||||||
if (list == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
needstats = f_inode || f_longform || f_size;
|
needstats = f_inode || f_longform || f_size;
|
||||||
flen = 0;
|
flen = 0;
|
||||||
btotal = 0;
|
btotal = 0;
|
||||||
@ -784,7 +780,13 @@ display(const FTSENT *p, FTSENT *list, int options)
|
|||||||
++entries;
|
++entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entries)
|
/*
|
||||||
|
* If there are no entries to display, we normally stop right
|
||||||
|
* here. However, we must continue if we have to display the
|
||||||
|
* total block count. In this case, we display the total only
|
||||||
|
* on the second (p != NULL) pass.
|
||||||
|
*/
|
||||||
|
if (!entries && (!(f_longform || f_size) || p == NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d.list = list;
|
d.list = list;
|
||||||
|
Loading…
Reference in New Issue
Block a user