From 8622cae73e18f4408e74914428090952e60473a2 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:53:32 +0800 Subject: [PATCH] du: warn on stat() failure (#515) * 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 --- bin/du | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/du b/bin/du index 853563ca..ebb26b76 100755 --- a/bin/du +++ b/bin/du @@ -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];