Skip to content

Commit 2d2b17a

Browse files
authored
ls: incorrect column widths in -R mode
* The column widths for "ls -R" didn't always look right * List() is called for each directory/subdirectory * Global variable $Maxlen is increased by 1 unconditionally, despite the value being saved from the previous call * When I tested "perl ls -R .." I observed $Maxlen values from 21-59, incrementing by 1 for each directory * The entries for the subdirectories are printed with too much space * When I compare the output of GNU ls, the column widths are calculated for each directory listed * Fix this by making $Maxlen a non-global; it is only used in List() and the value between calls should not be saved * Extra: remove unused variable $BlockSize
1 parent 8d0d173 commit 2d2b17a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

bin/ls

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ sub format_mode {
110110
# ------ define variables
111111
my $Getgrgid = ""; # getgrgid() for this platform
112112
my $Getpwuid = ""; # getpwuid() for this platform
113-
my $Maxlen = 1; # longest string we've seen
114113
my $Now = time; # time we were invoked
115114
my %Options = (); # option/flag arguments
116115
my $SixMonths = # long listing time if < 6 months, else year
@@ -314,12 +313,11 @@ sub List {
314313
my $Expand = shift; # do 1 level of dir expansion,
315314
# for "ls DIRNAME"
316315
my $Attributes = ""; # entry attributes hashref
317-
my $BlockSize = # block size in 512-byte units
318-
exists($Options->{'k'}) ? 2 : 1;
319316
my $Cols = 0; # output columns for this List()
320317
my $Entry = ""; # directory entry
321318
my @Dirs = (); # directories from -R and DirEntries
322319
my $Mask = ""; # sprintf() format/mask
320+
my $Maxlen = 1; # longest string for current directory
323321
my $Mylen = 0; # current entry length
324322
my $Path = ""; # path for subdirectories
325323
my $Piece = ""; # piece of entry list

0 commit comments

Comments
 (0)