Skip to content

Commit

Permalink
du: warn on stat() failure (#515)
Browse files Browse the repository at this point in the history
* du can take a number of file arguments
* GNU and OpenBSD versions will print a warning if a file fails to stat, then proceed to the next file
* test: "touch there1 there2 && perl du nothere1 nothere2 there1 there2" --> two warning lines and two du summary lines for empty files there1 & 2
  • Loading branch information
mknos committed Mar 23, 2024
1 parent 4823630 commit 8622cae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bin/du
Expand Up @@ -57,8 +57,10 @@ sub traverse {
my $total = 0;
local $depth = $depth + 1;
my @s = ($opt_L || $opt_H && $depth == 1) ? stat $fn : lstat $fn;
# If we can't stat the file, return silently
return 0 unless @s;
unless (@s) {
warn "$0: cannot access '$fn': $!\n";
return 0;
}
# Check for cross-filesystem traversals (-x option)
if ($depth == 1) {
$filesystem = $s[0];
Expand Down

0 comments on commit 8622cae

Please sign in to comment.