tag 291823 +patch
thanks

Attached is a quick and dirty perl script which can be used to browse a
report in a tree fashion using mc. Just put it into /usr/share/mc/extfs
and do:
echo cruftfs >> /usr/share/mc/extfs/extfs.ini

Then you can (in mc) do "cd cruft-report-file#cruftfs"

The size is the number of cruft-reported file below the current entry.
The perms are drwxrwxrwx if the entry was reported by cruft, and d--------- 
otherwise.
All entries are reported as directories, since it is impossible to
deduce the file type from cruft output, and I wanted to avoid statting
every file in the report.

I still have to figure out how and if get this integrated properly with
the package.

Marcin
-- 
Marcin Owsiany <[EMAIL PROTECTED]>             http://marcin.owsiany.pl/
GnuPG: 1024D/60F41216  FE67 DA2D 0ACA FC5E 3F75  D6F6 3A0D 8AA0 60F4 1216
#!/usr/bin/perl
use warnings;
use strict;

umask 077;
my $date;
chop($date=`LC_ALL=C date "+%b %d %Y %H:%M"`);

sub file { "-r--r--r--   1 root     root     0 $date $_[0]\n"; }
sub dir  { my $perms = $_[1] || 'd---------';
           my $size  = sprintf("%5d", $_[2] || 0);
           return "$perms   1 root     root $size $date $_[0]\n" ; }

sub dirname($)
{
        my $a = shift || '';
        return '' if $a eq '' or $a eq '/';
        $a =~ s#/[^/]*$##;
        return $a;
}

sub dolist
{
        my $file = shift;
        
        open REPORT, "<$file" or print file("ERROR-OPENING-REPORT") and exit 0;
        my %sections;
        my $last;
        my $lastfile;
        my @counter;
        while (<REPORT>) {
                if (/^---- (.*) ----/) {
                        $last = $1;
                        $last =~ s,/,_,g;
                        $sections{$last} = {};
                        $lastfile = '';
                } elsif (/^ {8}(.*)/) {
                        my $file = $1;
                        $sections{$last}->{$file} = [666,0];
                        
                        $file = dirname($file);
                        while ($file) {
                                if (! exists $sections{$last}->{$file}) {
                                        $sections{$last}->{$file} = [0,0];
                                }
                                $sections{$last}->{$file}->[1]++;
                                $file = dirname($file);
                        }
                }
        }
        close REPORT;
        foreach my $s (sort keys %sections) {
                print dir($s);
                foreach (sort keys %{$sections{$s}}) {
                        print dir($s.$_, $sections{$s}->{$_}->[0] ? 
'drwxrwxrwx' : '', $sections{$s}->{$_}->[1]) unless $_ eq '';
                }
        }
}

my $arg = shift @ARGV || '';
if    ($arg eq 'list') { dolist(@ARGV); exit 0; }
exit 1;

Reply via email to