#!/usr/bin/perl -w
##
# showstore.pl, michael@schaarwaechter.de, 2011/03
#
# Listet alle Dateien in $filelocation, die _nicht_ 
# im Programm erfasst sind.
# 
# Eine Parameter wird den ausgegebenen Dateien vorangestellt. 
# Aufruf mit ./showstore rm > temp.sh zum Beispiel erzeugt ein Shellscript,
# mit dem die Dateien geloescht werden koennen. Dieses Script selbst
# loescht nichts.

use DB_File;
use File::Basename;   

# -------------- Beginn Config
# Hier konfigurieren: Verzeichnis mit files.hash und den Dateien im Store
our $filelocation = '..';
# -------------- Ende Config
# 
our $hashlocation = "$filelocation/files.hash";
our $t="-#-";     

tie our %filenames, "DB_File", $hashlocation or die "Could not open $hashlocation: $!";

$fs=0;
$count=0;
$nuller=0;
foreach $file(glob("$filelocation/*")) {
   next if (not -f $file);
   $file=basename($file);
   next if ($file=~/\./); # Dateien mit Punkt werden ausgeschlossen
   if (not defined($filenames{$file})) {
      $count++;
      $fs+=-s "$filelocation/$file";
      $nuller++ if (not (-s "$filelocation/$file"));
      print join(" ",@ARGV)," $filelocation/$file\n";
   }
}
$fs=($fs/1024)/1024;
printf "# %.3f MB mit $count toten Dateien belegt, $nuller Dateien mit 0 Bytes Groesse\n",$fs;
untie %filenames;


