NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/58740: ls: flag -O incorrectly described in MAN and buggy



The following reply was made to PR bin/58740; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/58740: ls: flag -O incorrectly described in MAN and buggy
Date: Fri, 11 Oct 2024 22:06:56 +0000 (UTC)

 On Fri, 11 Oct 2024, tlaronde%kergis.com@localhost wrote:
 
 > Furthermore---this was found by Valery Ushakov---the implementation is buggy:
 >
 > $ mkdir -p 1/2/3/4
 > $ touch 1/2/200
 > $ find .
 >
 
 This is just a formatting issue. When `-P' is used, ls(1) should take into
 account the full pathname length when printing in multiple columns--it doesn't.
 This displays correctly if you force single-column mode:
 
 ls -1OPR ~
 
 > ls(1) has a non POSIX flag 'O' that is described as displaying only "leaf" files (files, not directory).
 >
 > This is not what it does: it only suppresses the display of the newline, dir and trailing ':' when going recursive.
 >
 
 Also fixed, below, I think--please try.
 
 ```
 diff -urN ls.orig/ls.c ls/ls.c
 --- ls.orig/ls.c	2024-02-03 01:51:38.676768149 +0000
 +++ ls/ls.c	2024-10-11 21:55:06.727238968 +0000
 @@ -552,8 +552,15 @@
   				continue;
   			}
   		}
 -		if (cur->fts_namelen > maxlen)
 -			maxlen = cur->fts_namelen;
 +		if (cur->fts_info == FTS_D && f_leafonly)
 +			cur->fts_number = NO_PRINT;
 +
 +		unsigned int ftslen = f_fullpath ?
 +			/* path + name + '/' */
 +			cur->fts_pathlen + cur->fts_namelen + 1 :
 +			cur->fts_namelen;
 +		if (ftslen > maxlen)
 +			maxlen = ftslen;
   		if (needstats) {
   			sp = cur->fts_statp;
   			if (sp->st_blocks > maxblock)
 ```
 
 -RVP
 


Home | Main Index | Thread Index | Old Index