#!/usr/local/bin/perl5.7.1 -w

use File::PathConvert 'realpath';
use strict;

sub lookat {
  my ($entry) = @_;
  my $name = "lookat";
  my (@files);

  return if exists($dirs{$entry});

  print "\t$name -> traversing $entry\n" if DEBUG & TRAVERSE;
  $dirs{$entry} = {};

  opendir DIR, $entry or die "can't open $entry: $!\n";
  for (grep !/^\.\.?$/, readdir DIR) {
    next if exists($ignore{$_});

    my $file = "$entry/$_";
    $file =~ s!//!/!g;
    
    my @stats = ( '0', (lstat $file)[0,1,7,9] );

    if (-r _ && -f _) {
      print "\t\t$name -> F $file\n" if DEBUG & REPORT;
      $dirs{$entry}{$_} = \@stats;
    }
    elsif (-r _ && -d _ && -x _) {
      print "\t\t$name -> D $file\n" if DEBUG & REPORT;
      lookat($file) unless exists($opts{norecurse});
    } 
  }
  closedir(DIR);
}
