Subject: | Bug following links in Filesys::DiskUsage |
This is with Perl 5.8.1 on Linux kernel 2.4.21
Part of your code checks for (-l && $config{dereference}). If dereference fails, it goes onto the next elsif statement. However, if a link is to a directory, (-d) is also true. Same with a file and (-f), so it ends up dereferencing anyway. Below is a diff with my suggested changes:
--- DiskUsage.pm.orig 2005-01-18 17:27:04.000000000 -0800
+++ DiskUsage.pm 2005-01-18 17:17:07.000000000 -0800
@@ -161,10 +161,14 @@
# calculate sizes
for (@_) {
- if (-l && $config{dereference}) { # is a symbolic link
- $sizes{$_} = du( { 'recursive' => $config{'recursive'},
+ if (-l) { # is symbolic link
+ if ($config{'dereference'}) { # We want to follow it
+ $sizes{$_} = du( { 'recursive' => $config{'recursive'},
'exclude' => $config{'exclude'},
}, readlink($_));
+ } else {
+ next;
+ }
}
elsif (-f) { # is a file
if (defined $config{exclude}) {