<commit_before>#!/usr/bin/perl
#
# (C) 2002, <NAME>
#

#
# Finds under a dbfarm directory all database directories, 
# i.e., directories in which a BBP.dir file resides.
# Next, finds all bats in that database directory that are stored on disk,
# but do not exist in the BBP.
#
# Usage example (DISCLAIMER!):
#   ./findtmpbats.pl ~/data/monetdb | xargs rm -f
# 

use File::Find;

sub usage() {
  print "Usage: $0 <dbfarm>\n";
  exit -1;
}

my $dbfarm      = shift || usage;
my @dbs         = ();
my %bats        = ();

sub readBBP ($) {
  my $dbdir = shift;
  open BBP, "<$dbdir/BBP.dir";
  <BBP>;
  while (<BBP>) {
    my @fs = split /,\s+/;
    $bats{$fs[3]}++;
  }
  close BBP;
}

sub checkBBP ($) {
  my $dbdir = shift;
  # print $dbdir, "\n";
  %bats = ();
  readBBP $dbdir;
  find(\&findtmpbats, $dbdir);
}

sub findtmpbats {
  return unless -f;
  return unless $File::Find::name =~ m|bat/(\d+)/?(\d+)?|;
  my $bat = $1;
  $bat .= "/" . $2 if defined $2;
  print $File::Find::name, "\n" if not defined $bats{$bat};
}

#
# Main:
#

find 
  sub { 
    push @dbs, $1 if -f && $File::Find::name =~ m|(.*)/BBP.dir|; 
  }, 
  $dbfarm;
map { checkBBP $_; } @dbs;

<commit_msg>deeper hierarchies than I thought... only happens with very many bats. now works for those cases as well.<commit_after>#!/usr/bin/perl
#
# (C) 2002, <NAME>
#

#
# Finds under a dbfarm directory all database directories, 
# i.e., directories in which a BBP.dir file resides.
# Next, finds all bats in that database directory that are stored on disk,
# but do not exist in the BBP.
#
# Usage example (DISCLAIMER!):
#   ./findtmpbats.pl ~/data/monetdb | xargs rm -f
# 

use File::Find;

sub usage() {
  print "Usage: $0 <dbfarm>\n";
  exit -1;
}

my $dbfarm      = shift || usage;
my @dbs         = ();
my %bats        = ();

sub readBBP ($) {
  my $dbdir = shift;
  open BBP, "<$dbdir/BBP.dir";
  <BBP>;
  while (<BBP>) {
    my @fs = split /,\s*/;
    $bats{$fs[3]}++;
  }
  close BBP;
}

sub checkBBP ($) {
  my $dbdir = shift;
  # print $dbdir, "\n";
  %bats = ();
  readBBP $dbdir;
  find(\&findtmpbats, $dbdir);
}

sub findtmpbats {
  return unless -f;
  return unless $File::Find::name =~ m|bat/(\d+)|gc;
  my $bat = $1;
  $bat .= $1 while $File::Find::name =~ m|(/\d+)|gc;
  print $File::Find::name, "\n" if not defined $bats{$bat};
}

#
# Main:
#

find 
  sub { 
    push @dbs, $1 if -f && $File::Find::name =~ m|(.*)/BBP.dir|; 
  }, 
  $dbfarm;
map { checkBBP $_; } @dbs;
{'fraction_non_alphanumeric': 0.1993477374643294, 'fraction_numerical': 0.008560945780676722, 'mean_word_length': 2.787037037037037, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1863763', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1024, 'n_words': 287}