Skip to content

Commit 165f960

Browse files
authored
ls: runtime error for non-existent file argument
* When testing ls today I discovered the error: Can't use an undefined value as a HASH reference at ls line 525. * Test case: "perl ls xxx ar a.x pig" where files xxx and a.x don't exist * I broke this in the previous commit around where DirEntries() is called for Files-list * Add correct return value guard to fix error * DirEntries() prints a warning and returns an empty list if stat() fails on its file argument * Derive sorted-list from attrs-hash to avoid listing filenames where stat() failed %perl ls xxx ar a.x pig ls: can't access 'xxx': No such file or directory ls: can't access 'a.x': No such file or directory ar pig
1 parent 51ac8d3 commit 165f960

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

bin/ls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,10 @@ if ($#ARGV < 0) {
522522
my %attrs;
523523
foreach (@Files) {
524524
my @ret = DirEntries(\%Options, $_);
525+
next unless @ret; # stat() failed
525526
%attrs = (%attrs, %{ $ret[-1] });
526527
}
527-
my @sorted = Order(\%Options, \%Attributes, @Files);
528+
my @sorted = Order(\%Options, \%Attributes, keys %attrs);
528529
List('.', \%Options, 0, 0, @sorted, \%attrs);
529530
}
530531
for my $Arg (@Dirs) {

0 commit comments

Comments
 (0)