Don't include sub-folders in a folder size
authorJamie Cameron <jcameron@webmin.com>
Wed, 11 Nov 2009 23:21:59 +0000 (15:21 -0800)
committerJamie Cameron <jcameron@webmin.com>
Wed, 11 Nov 2009 23:21:59 +0000 (15:21 -0800)
mailboxes/folders-lib.pl
web-lib-funcs.pl

index 2834013..cdba7e3 100755 (executable)
@@ -2356,8 +2356,9 @@ foreach $f (@_) {
                $f->{'size'} = $st[7];
                }
        elsif ($f->{'type'} == 1) {
-               # Maildir folder size is that of all files in it
-               $f->{'size'} = &recursive_disk_usage($f->{'file'});
+               # Maildir folder size is that of all files in it, except
+               # sub-folders.
+               $f->{'size'} = &recursive_disk_usage($f->{'file'}, '^\\.');
                }
        elsif ($f->{'type'} == 3) {
                # MH folder size is that of all mail files
index a87005f..baaee94 100755 (executable)
@@ -5938,7 +5938,7 @@ if ($ex) {
 return $out =~ /^([0-9]+)/ ? $1 : "???";
 }
 
-=head2 recursive_disk_usage(directory)
+=head2 recursive_disk_usage(directory, [skip-regexp], [only-regexp])
 
 Returns the number of bytes taken up by all files in some directory and all
 sub-directories, by summing up their lengths. The disk_usage_kb is more
@@ -5949,6 +5949,8 @@ reflective of reality, as the filesystem typically pads file sizes to 1k or
 sub recursive_disk_usage
 {
 my $dir = &translate_filename($_[0]);
+my $skip = $_[1];
+my $only = $_[2];
 if (-l $dir) {
        return 0;
        }
@@ -5963,7 +5965,9 @@ else {
        closedir(DIR);
        foreach my $f (@files) {
                next if ($f eq "." || $f eq "..");
-               $rv += &recursive_disk_usage("$dir/$f");
+               next if ($skip && $f =~ /$skip/);
+               next if ($only && $f !~ /$only/);
+               $rv += &recursive_disk_usage("$dir/$f", $skip, $only);
                }
        return $rv;
        }