Files
entropy/handlers/md5sum.php
T
2007-07-20 10:38:38 +00:00

54 lines
1.4 KiB
PHP

<?php
function insert_package($pkgfile,$pkgpath,$db) {
$mtime = filemtime($pkgpath);
$md5 = md5_file($pkgpath);
$sql = "insert into checksums (filename,mtime,md5) values ('".$pkgfile."', '".$mtime."', '".$md5."')";
sqlite_query($db, $sql);
return $md5;
}
function delete_package($pkgfile,$db) {
$sql = "delete from checksums where filename ='".$pkgfile."';";
sqlite_query($db, $sql);
}
$pkgfile = urlencode($_GET['package']);
$pkgarch = $_GET['arch'];
$pkgpath = "/home/fabio/entropy/packages/" . $pkgarch . "/" . $pkgfile;
if (!file_exists($pkgpath))
print("-1");
$dbfile = "/home/fabio/public_html/svn.sabayonlinux.org/entropy/handlers/checksums.db";
if (file_exists($dbfile)) {
$db = sqlite_open($dbfile);
} else {
$db = sqlite_open($dbfile);
sqlite_query($db,"create table checksums (filename varchar(255) primary key , mtime int, md5 int);");
}
$mtime = filemtime($pkgpath);
$sql = "select * from checksums where filename ='".$pkgfile."';";
$result = sqlite_query($db, $sql);
$row = sqlite_fetch_array($result);
if(!$row) {
$md5 = insert_package($pkgfile,$pkgpath,$db);
print($md5);
} else {
// check if mtime is valid
$dbmtime = $row['mtime'];
if ($dbmtime == $mtime) {
print($row['md5']);
} else {
delete_package($pkgfile,$db);
$md5 = insert_package($pkgfile,$pkgpath,$db);
print($md5);
}
}
sqlite_close($db);
?>