56 lines
1.3 KiB
Perl
56 lines
1.3 KiB
Perl
#!/usr/bin/perl
|
|
|
|
# This file (c) 2013 Solomon Peachy is licensed under the GPLv3.
|
|
# It is being provided for illustration purposes only. USE AT YOUR OWN RISK.
|
|
|
|
# This script validates the files in a repository. If something is missing
|
|
# or fails a checksum, complain loudly.
|
|
|
|
use strict;
|
|
use DBI;
|
|
|
|
use Digest::SHA1;
|
|
|
|
my $href;
|
|
my %list;
|
|
|
|
my $db_user = "po_user";
|
|
my $db_pass = "po_pass";
|
|
my $dsn = "dbi:Pg:dbname=po_db";
|
|
my $repo_path = "/path/to/po/repo";
|
|
my $offset = $ARGV[0];
|
|
my $limit = $ARGV[1];
|
|
|
|
my $dbh = DBI->connect($dsn, $db_user, $db_pass,
|
|
{ AutoCommit => 0}) || die($DBI::errstr);
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
my $select = "select sha1sum,path from files order by path offset $offset limit $limit";
|
|
my $stmt = $dbh->prepare($select);
|
|
$stmt->execute();
|
|
my $i = $offset;
|
|
$limit = $stmt->rows;
|
|
$limit += $offset;
|
|
while (my $href = $stmt->fetchrow_hashref()) {
|
|
my $sha1 = Digest::SHA1->new;
|
|
$i++;
|
|
if (!open(FILE, "<$repo_path/$$href{path}")) {
|
|
print "ERROR: missing '$$href{path}' \n";
|
|
next;
|
|
}
|
|
printf("%d/%d: '%s' \r", $i, $limit, $$href{'path'});
|
|
$sha1->addfile(*FILE);
|
|
my $res = $sha1->hexdigest;
|
|
if ($res != $$href{'sha1sum'}) {
|
|
print "ERROR: sha1sum '$$href{path}' \n";
|
|
}
|
|
close(FILE);
|
|
}
|
|
print "\n";
|
|
|
|
|
|
$stmt->finish();
|
|
|
|
$dbh->disconnect();
|
|
|