connect_error)
die_500("Connection to database failed: " . $mysql->connect_error);
if (! $mysql_result = $mysql -> query(
"SELECT DISTINCT " .
"`binary_packages`.`id`," .
"`binary_packages`.`pkgname`," .
"`package_sources`.`pkgbase`," .
"CONCAT(" .
"IF(`binary_packages`.`epoch`=\"0\",\"\",CONCAT(`binary_packages`.`epoch`,\":\"))," .
"`binary_packages`.`pkgver`,\"-\"," .
"`binary_packages`.`pkgrel`,\".\"," .
"`binary_packages`.`sub_pkgrel`" .
") AS `version`," .
"`repositories`.`stability` AS `repo_stability`," .
"`repository_stabilities`.`name` AS `repo_stability_name`," .
"`repositories`.`name` AS `repo`," .
"`architectures`.`name` AS `arch`," .
"`git_repositories`.`name` AS `git_repo`," .
"`package_sources`.`uses_upstream`," .
"`package_sources`.`uses_modification`" .
" FROM `binary_packages`" .
" JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" .
" JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" .
" JOIN `repository_stabilities` ON `repositories`.`stability`=`repository_stabilities`.`id`" .
" JOIN `build_assignments` ON `binary_packages`.`build_assignment`=`build_assignments`.`id`" .
" JOIN `package_sources` ON `build_assignments`.`package_source`=`package_sources`.`id`" .
" JOIN `upstream_repositories` ON `package_sources`.`upstream_package_repository`=`upstream_repositories`.`id`" .
" JOIN `git_repositories` ON `upstream_repositories`.`git_repository`=`git_repositories`.`id`" .
" WHERE `binary_packages`.`pkgname`=from_base64(\"" . base64_encode($_GET["pkgname"]) . "\")" .
" AND `architectures`.`name`=from_base64(\"" . base64_encode($_GET["arch"]) . "\")" .
" AND `repositories`.`name`=from_base64(\"" . base64_encode($_GET["repo"]) . "\")"
))
die_500("Query failed: " . $mysql->error);
if ($mysql_result -> num_rows != 1)
throw_http_error(404, "Package Not Found In Buildmaster's Database");
$mysql_content = $mysql_result -> fetch_assoc();
$same_keys = array (
array("mysql" => "pkgname", "json" => "Name"),
array("mysql" => "version", "json" => "Version", "suffix_diff" => ".0"),
array("mysql" => "repo", "json" => "Repository"),
array("mysql" => "arch", "json" => "Architecture")
);
foreach ($same_keys as $same_key)
if (($mysql_content[$same_key["mysql"]] != $json_content[$same_key["json"]]) &&
((!isset($same_key["suffix_diff"])) ||
($mysql_content[$same_key["mysql"]] != $json_content[$same_key["json"]].$same_key["suffix_diff"])))
die_500("Inconsistency in Database found:
\n" .
"buildmaster[" . $same_key["mysql"] . "] != repositories[" . $same_key["json"] . "]:
\n" .
"\"" . $mysql_content[$same_key["mysql"]] . "\" != \"" . $json_content[$same_key["json"]] . "\"");
// query _all_ dependencies
if (! $mysql_result = $mysql -> query(
"SELECT DISTINCT " .
"`dependency_types`.`name` AS `dependency_type`," .
"GROUP_CONCAT(" .
"CONCAT(\"\\\"\",`install_target_providers`.`id`,\"\\\": \",\"{\\n\"," .
"\" \\\"repo\\\": \\\"\",`repositories`.`name`,\"\\\",\\n\"," .
"\" \\\"arch\\\": \\\"\",`architectures`.`name`,\"\\\",\\n\"," .
"\" \\\"pkgname\\\": \\\"\",`binary_packages`.`pkgname`,\"\\\"\\n\"," .
"\"}\"" .
")) AS `deps`," .
"`install_targets`.`name` AS `install_target`" .
" FROM `dependencies`" .
" JOIN `dependency_types` ON `dependency_types`.`id`=`dependencies`.`dependency_type`" .
" JOIN `install_targets` ON `install_targets`.`id`=`dependencies`.`depending_on`" .
" AND `install_targets`.`name` NOT IN (\"base\",\"base-devel\")" .
" LEFT JOIN (" .
"`install_target_providers`" .
" JOIN `binary_packages` ON `install_target_providers`.`package`=`binary_packages`.`id`" .
" JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" .
" JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" .
" JOIN `repository_stability_relations` ON `repository_stability_relations`.`more_stable`=`repositories`.`stability`" .
" AND `repository_stability_relations`.`less_stable`=" . $mysql_content["repo_stability"] .
") ON `install_target_providers`.`install_target`=`dependencies`.`depending_on`" .
" WHERE `dependencies`.`dependent`=" . $mysql_content["id"] .
" AND NOT EXISTS (" .
"SELECT 1 FROM `binary_packages` AS `subst_bp`" .
" JOIN `repositories` AS `subst_r` ON `subst_bp`.`repository`=`subst_r`.`id`" .
// the substitue must be truly less stable than the dependency
" JOIN `repository_stability_relations` AS `subst_rsr` ON `subst_rsr`.`less_stable`=`subst_r`.`stability`" .
" AND `subst_rsr`.`less_stable`!=`subst_rsr`.`more_stable`" .
// and more (or equally) stable than us
" JOIN `repository_stability_relations` AS `subst_rsr2` ON `subst_rsr2`.`more_stable`=`subst_r`.`stability`" .
" WHERE `subst_bp`.`pkgname`=`binary_packages`.`pkgname`" .
" AND `subst_rsr`.`more_stable`=`repositories`.`stability`" .
" AND `subst_rsr2`.`less_stable`=" . $mysql_content["repo_stability"] .
")" .
" GROUP BY `install_targets`.`id`,`dependency_types`.`id`" .
" ORDER BY FIELD (`dependency_types`.`name`,\"run\",\"make\",\"check\",\"link\"), `install_targets`.`name`"
))
die_500("Query failed: " . $mysql->error);
$dependencies = array();
while ($row = $mysql_result -> fetch_assoc()) {
$row["deps"] = json_decode("{".$row["deps"]."}",true);
$dependencies[] = $row;
}
function dependency_is_runtime($dep) {
return $dep["dependency_type"]=="run";
};
function dependency_extract_name($dep) {
return $dep["install_target"];
};
$dep_it = array_filter( $dependencies, "dependency_is_runtime");
$dep_it = array_map("dependency_extract_name", $dep_it);
$dep_it = preg_replace("/[<=>].*$/","",$dep_it);
$js_dep = preg_replace("/[<=>].*$/","",$json_content["Depends On"]);
$dep_errors = implode(
", ",
array_diff(
array_merge($dep_it,$js_dep),
array_intersect($dep_it,$js_dep)
)
);
if ($dep_errors != "")
die_500(
"Dependencies differ: " . $dep_errors. "
\n" .
"mysql: " . implode(", ",$dep_it) . "
\n" .
"json: " . implode(", ",$js_dep)
);
// query dependent packages
if (! $mysql_result = $mysql -> query(
"SELECT DISTINCT " .
"`dependency_types`.`name` AS `dependency_type`," .
"`install_targets`.`name` AS `install_target`," .
"`repositories`.`name` AS `repo`," .
"`architectures`.`name` AS `arch`," .
"`binary_packages`.`pkgname`" .
" FROM `install_target_providers`" .
" JOIN `install_targets` ON `install_targets`.`id`=`install_target_providers`.`install_target`" .
" AND `install_targets`.`name` NOT IN (\"base\",\"base-devel\")" .
" JOIN `dependencies` ON `install_target_providers`.`install_target`=`dependencies`.`depending_on`" .
" JOIN `dependency_types` ON `dependency_types`.`id`=`dependencies`.`dependency_type`" .
" JOIN `binary_packages` ON `dependencies`.`dependent`=`binary_packages`.`id`" .
" JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" .
" JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" .
" JOIN `repository_stability_relations` ON `repository_stability_relations`.`less_stable`=`repositories`.`stability`" .
" AND `repository_stability_relations`.`more_stable`=" . $mysql_content["repo_stability"] .
" WHERE `install_target_providers`.`package`=" . $mysql_content["id"] .
" AND NOT EXISTS (" .
"SELECT 1 FROM `binary_packages` AS `subst_bp`" .
" JOIN `repositories` AS `subst_r` ON `subst_bp`.`repository`=`subst_r`.`id`" .
// the substitue must be truly less stable than we
" JOIN `repository_stability_relations` AS `subst_rsr` ON `subst_rsr`.`less_stable`=`subst_r`.`stability`" .
" AND `subst_rsr`.`less_stable`!=`subst_rsr`.`more_stable`" .
// and more (or equally) stable than the required-by
" JOIN `repository_stability_relations` AS `subst_rsr2` ON `subst_rsr2`.`more_stable`=`subst_r`.`stability`" .
" WHERE `subst_bp`.`pkgname`=from_base64(\"" . base64_encode($mysql_content["pkgname"]) . "\")" .
" AND `subst_rsr2`.`less_stable`=`repositories`.`stability`" .
" AND `subst_rsr`.`more_stable`=" . $mysql_content["repo_stability"] .
")" .
" GROUP BY `binary_packages`.`id`,`dependency_types`.`id`" .
" ORDER BY FIELD (`dependency_types`.`name`,\"run\",\"make\",\"check\",\"link\"), `install_targets`.`name`!=`binary_packages`.`pkgname`, `install_targets`.`name`, `binary_packages`.`pkgname`"
))
die_500("Query failed: " . $mysql->error);
$dependent = array();
while ($row = $mysql_result -> fetch_assoc())
$dependent[] = $row;
$content = array_merge($mysql_content,$json_content);
// query substitutes
if (! $mysql_result = $mysql -> query(
"SELECT " .
"`binary_packages`.`pkgname` AS `pkgname`," .
"`repositories`.`name` AS `repo`," .
"`repositories`.`is_on_master_mirror`," .
"`architectures`.`name` AS `arch`," .
"CONCAT(" .
"IF(`binary_packages`.`epoch`=\"0\",\"\",CONCAT(`binary_packages`.`epoch`,\":\"))," .
"`binary_packages`.`pkgver`,\"-\"," .
"`binary_packages`.`pkgrel`,\".\"," .
"`binary_packages`.`sub_pkgrel`" .
") AS `version`" .
" FROM `binary_packages` " .
" JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" .
" JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" .
" JOIN `binary_packages` AS `original`" .
" ON `binary_packages`.`pkgname`=`original`.`pkgname`" .
" AND `binary_packages`.`id`!=`original`.`id`" .
" WHERE `original`.`id`=" . $mysql_content["id"]
))
die_500("Query failed: " . $mysql->error);
$elsewhere = array();
while ($row = $mysql_result -> fetch_assoc())
$elsewhere[] = $row;
?>
Arch Linux 32 - )