Files
entropy/handlers/md5sum.php
(no author) 4e7ebfe412 small fixes
git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@803 cd1c1023-2f26-0410-ae45-c471fc1f0318
2007-12-05 14:43:20 +00:00

58 lines
1.3 KiB
PHP

<?php
function insert_package($pkgpath,$db) {
$mtime = filemtime($pkgpath);
$md5 = md5_file($pkgpath);
$sql = "insert into checksums (filename,mtime,md5) values ('".$pkgpath."', '".$mtime."', '".$md5."')";
sqlite_query($db, $sql);
return $md5;
}
function delete_package($pkgpath,$db) {
$sql = "delete from checksums where filename ='".$pkgpath."';";
sqlite_query($db, $sql);
}
$pkgfile = rawurldecode($_GET['package']);
$pkgarch = $_GET['arch'];
$pkgpath = "../packages/" . $pkgarch . "/" . $pkgfile;
if (!file_exists($pkgpath)) {
print("-1");
return;
}
$dbfile = "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 ='".$pkgpath."';";
$result = sqlite_query($db, $sql);
$row = sqlite_fetch_array($result);
if(!$row) {
$md5 = insert_package($pkgpath,$db);
print($md5);
} else {
// check if mtime is valid
$dbmtime = $row['mtime'];
if ($dbmtime == $mtime) {
print($row['md5']);
} else {
delete_package($pkgpath,$db);
$md5 = insert_package($pkgpath,$db);
print($md5);
}
}
sqlite_close($db);
?>