#!/usr/bin/perl
use DBI;
use strict;
my $db = DBI->connect("dbi:mysql:database=ext2backup", "root", "")
	or die $DBI::errstr;
my $inserter = $db->prepare(
	"INSERT INTO `entries`(`inode`,`curdir`,`name`, `size`) VALUES (?,?,?,?)");
my $counter = 0;
my $curdir = undef;
while (<>) {
	my @chunks = split /    /;
	foreach my $chunk (@chunks) {
		$chunk =~ s/ +$//;
		if ($chunk =~ /^ ?([0-9]+)  \(([0-9]+)\) (.*)$/) {
			my ($inode, $size, $name) = ($1, $2, $3);
			if ($name eq ".") {
				$curdir = $inode;
			}
			# print "($inode, $size, $name) at $curdir\n";
			$inserter->execute($inode, $curdir, $name, $size)
				or die $DBI::errstr;
		}
		else {
			die "Invalid chunk: $chunk"
		}
	}
	$counter++;
	if (($counter % 100) == 0) {
		print "$counter lines...\n";
	}
}

# vim:set tabstop=4 softtabstop=4 shiftwidth=4: 
# vim:set foldmethod=marker foldlevel=32 foldmarker={,}: 
