connect('localhost', 11211) or die ('Memcached Connection Error');
$pkgapi_reachable = $memcache -> get('pkgapi_reachable');
$tld = explode('.', $_SERVER['HTTP_HOST']);
end($tld);
$tld = current($tld);
if (array_key_exists('HTTPS', $_SERVER) && ($_SERVER['HTTPS'] == 'on'))
$protocol = 'https';
else
$protocol = 'http';
if ($pkgapi_reachable === false) {
if (site_is_reachable($protocol . '://pkgapi.archlinux32.' . $tld . '/'))
$pkgapi_reachable = 'YES';
else
$pkgapi_reachable = 'NO';
$memcache -> set('pkgapi_reachable', $pkgapi_reachable, 0, 300);
}
if ($pkgapi_reachable == 'YES')
$skip_json_checks = false;
else
$skip_json_checks = true;
if (!$skip_json_checks) {
$json_content = json_decode(
file_get_contents(
$protocol . '://pkgapi.archlinux32.' . $tld . '/' .
urlencode($_GET["arch"]) . '/' .
urlencode($_GET["repo"]) . '/' .
urlencode($_GET["pkgname"])
),
true
);
if (!isset($json_content) || !array_key_exists('Name', $json_content)) {
//throw_http_error(404, "Package Not Found In Sync Database");
unset($json_content);
$skip_json_checks = true;
};
}
$mysql_result = mysql_run_query(
"SELECT " .
"`binary_packages`.`id`," .
"`binary_packages`.`pkgname`," .
"`sp_q`.`split_packages`," .
"`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`," .
"MAX(`binary_packages_in_repositories`.`last_moved`) AS `last_moved`," .
"`sr`.`name` AS `stable_repo`" .
" FROM `binary_packages`" .
mysql_join_binary_packages_architectures() .
mysql_join_binary_packages_binary_packages_in_repositories() .
mysql_join_binary_packages_in_repositories_repositories() .
mysql_join_repositories_repository_stabilities() .
mysql_join_binary_packages_build_assignments() .
mysql_join_build_assignments_package_sources() .
mysql_join_package_sources_upstream_repositories() .
mysql_join_upstream_repositories_git_repositories() .
mysql_join_upstream_repositories_repository_moves() .
" JOIN `repositories` AS `sr` ON `sr`.`id`=`repository_moves`.`to_repository`" .
" JOIN (" .
"SELECT DISTINCT `binary_packages`.`build_assignment`," .
"GROUP_CONCAT(" .
"CONCAT(" .
"\"\\\"\",`binary_packages`.`id`,\"\\\": {" .
"\\\"pkgname\\\":" .
" \\\"\",`binary_packages`.`pkgname`,\"\\\"," .
"\\\"repository\\\":" .
" \\\"\",`repositories`.`name`,\"\\\"," .
"\\\"repo_arch\\\":" .
" \\\"\",`architectures`.`name`,\"\\\"" .
"}\"" .
")" .
") AS `split_packages`" .
" FROM `binary_packages`" .
mysql_join_binary_packages_binary_packages_in_repositories() .
mysql_join_binary_packages_in_repositories_repositories() .
mysql_join_repositories_architectures() .
" GROUP BY `binary_packages`.`build_assignment`" .
") AS `sp_q`" .
" ON `sp_q`.`build_assignment`=`build_assignments`.`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"]) . "\")" .
" AND NOT EXISTS (" .
"SELECT 1" .
" FROM `repository_moves` AS `rm`" .
" WHERE `rm`.`from_repository`=`sr`.`id`" .
")" .
" GROUP BY `binary_packages`.`id`"
);
if ($mysql_result -> num_rows != 1)
throw_http_error(404, "Package Not Found In Buildmaster's Database");
$mysql_content = $mysql_result -> fetch_assoc();
$mysql_content["split_packages"] = array_map("unserialize", array_unique(array_map("serialize", json_decode("{".$mysql_content["split_packages"]."}",true))));
if (!$skip_json_checks) {
$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"]]) &&
((!array_key_exists('suffix_diff', $same_key)) ||
($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
$mysql_result = mysql_run_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\"," .
"\" \\\"is_to_be_deleted\\\": \\\"\",IF(`binary_packages_in_repositories`.`is_to_be_deleted`,\"1\",\"0\"),\"\\\"\\n\"," .
"\"}\"" .
")) AS `deps`," .
"IF(" .
"(" .
"`versions`.`order`=1 AND `dependencies`.`version_relation`=\">=\"" .
") OR (" .
"`versions`.`epoch`=8388607 AND `dependencies`.`version_relation`=\"<\"" .
")," .
"\"\"," .
"CONCAT(" .
"`dependencies`.`version_relation`," .
"IF(" .
"`versions`.`epoch`=0," .
"\"\"," .
"CONCAT(" .
"`versions`.`epoch`," .
"\":\"" .
")" .
")," .
"`versions`.`version`" .
")" .
") AS `version`," .
"`install_targets`.`name` AS `install_target`" .
" FROM `dependencies`" .
" LEFT JOIN (".
"`binary_packages_in_repositories` AS `bpir`" .
mysql_join_binary_packages_in_repositories_repositories('bpir','r') .
") ON `bpir`.`package`=`dependencies`.`dependent`" .
mysql_join_dependencies_dependency_types() .
mysql_join_dependencies_install_targets() .
" AND `install_targets`.`name` NOT IN (\"base\",\"base-devel\")" .
mysql_join_dependencies_versions() .
" LEFT JOIN (" .
"`install_target_providers`" .
mysql_join_install_target_providers_binary_packages() .
mysql_join_binary_packages_architectures() .
mysql_join_binary_packages_binary_packages_in_repositories() .
mysql_join_binary_packages_in_repositories_repositories() .
" 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`" .
" AND `repositories`.`architecture`=`r`.`architecture`" .
" WHERE `dependencies`.`dependent`=" . $mysql_content["id"] .
" AND NOT EXISTS (" .
"SELECT 1 FROM `binary_packages` AS `subst_bp`" .
mysql_join_binary_packages_binary_packages_in_repositories('subst_bp','subst_bpir') .
mysql_join_binary_packages_in_repositories_repositories('subst_bpir','subst_r') .
// 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 CONCAT(`install_targets`.`id`,\"-\",`versions`.`id`),`dependency_types`.`id`" .
" ORDER BY FIELD (`dependency_types`.`name`,\"run\",\"make\",\"check\",\"link\"), `install_targets`.`name`"
);
$dependencies = array();
while ($row = $mysql_result -> fetch_assoc()) {
$row["deps"] = array_map("unserialize", array_unique(array_map("serialize", json_decode("{".$row["deps"]."}",true))));
$dependencies[] = $row;
}
if (!$skip_json_checks) {
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"]);
if (!is_array($js_dep))
$js_dep = array();
if (!isset($dep_it))
$dep_it = array();
$dep_errors = implode(
", ",
array_diff(
array_merge($dep_it,$js_dep),
$dep_it
)
);
if ($dep_errors != "")
die_500(
"Dependencies differ: " . $dep_errors. "
\n" .
"mysql: " . implode(", ",$dep_it) . "
\n" .
"json: " . implode(", ",$js_dep)
);
foreach ($dependencies as $key => $dep) {
if ($dep["dependency_type"]!="run") {
$dependencies[$key]["json"]="not required";
continue;
}
foreach ($js_dep as $js)
if ($js == preg_replace("/[<=>].*$/","",$dep["install_target"]))
$dependencies[$key]["json"]=$js;
}
}
// query dependent packages
$mysql_result = mysql_run_query(
"SELECT DISTINCT " .
"`dependency_types`.`name` AS `dependency_type`," .
"`install_targets`.`name` AS `install_target`," .
"`repositories`.`name` AS `repo`," .
"`repositories`.`is_on_master_mirror`," .
"`architectures`.`name` AS `arch`," .
"`binary_packages`.`pkgname`," .
"IF(`binary_packages_in_repositories`.`is_to_be_deleted`,1,0) AS `is_to_be_deleted`" .
" FROM `install_target_providers`" .
" LEFT JOIN (".
"`binary_packages_in_repositories` AS `bpir`" .
mysql_join_binary_packages_in_repositories_repositories('bpir','r') .
") ON `bpir`.`package`=`install_target_providers`.`package`" .
mysql_join_install_target_providers_install_targets() .
" AND `install_targets`.`name` NOT IN (\"base\",\"base-devel\")" .
mysql_join_install_target_providers_dependencies() .
mysql_join_dependencies_dependency_types() .
mysql_join_dependencies_binary_packages() .
mysql_join_binary_packages_architectures() .
mysql_join_binary_packages_binary_packages_in_repositories() .
mysql_join_binary_packages_in_repositories_repositories() .
" AND `repositories`.`architecture`=`r`.`architecture`" .
" 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`" .
mysql_join_binary_packages_binary_packages_in_repositories('subst_bp','subst_bpir') .
mysql_join_binary_packages_in_repositories_repositories('subst_bpir','subst_r') .
// 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`," .
" `repositories`.`stability`," .
" `repositories`.`name`"
);
$dependent = array();
while ($row = $mysql_result -> fetch_assoc())
$dependent[] = $row;
if ($skip_json_checks)
$content = $mysql_content;
else
$content = array_merge($mysql_content,$json_content);
// query substitutes
$mysql_result = mysql_run_query(
"SELECT " .
"`binary_packages`.`pkgname` AS `pkgname`," .
"IF(`binary_packages_in_repositories`.`is_to_be_deleted`,1,0) AS `is_to_be_deleted`," .
"`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` " .
mysql_join_binary_packages_architectures() .
mysql_join_binary_packages_binary_packages_in_repositories() .
mysql_join_binary_packages_in_repositories_repositories() .
" JOIN `binary_packages` AS `original`" .
" ON `binary_packages`.`pkgname`=`original`.`pkgname`" .
" AND `binary_packages`.`id`!=`original`.`id`" .
" WHERE `original`.`id`=" . $mysql_content["id"]
);
$elsewhere = array();
while ($row = $mysql_result -> fetch_assoc())
$elsewhere[] = $row;
print_header($content["pkgname"] . " " . $content["version"] . " (" . $content["arch"] . ")");
?>
Architecture: | " title="Browse packages for architecture"> |
---|---|
Repository: | " title="Browse the repository"> |
\n"; print " Split Packages:\n"; print " | \n"; print "\n"; foreach ($content["split_packages"] as $split_package) { print " "; if ($split_package["pkgname"] != $content["pkgname"]) { print ""; } print $split_package["pkgname"]; $count --; if ($split_package["pkgname"] != $content["pkgname"]) print ""; if ($count > 0) print ", "; } if ($content["pkgname"] != $content["pkgbase"]) print " (" . $content["pkgbase"] . ")"; print "\n"; print " | \n"; print "
Description: | not found in pkg-api")."\n"; ?> |
Upstream URL: | " title="Visit the website for ">not found in pkg-api"); ?> |
License(s): | not found in pkg-api"); if (is_array($licenses)) print implode(", ",$licenses); else print $licenses; print "\n"; ?> |
Package Size: | not found in pkg-api")."\n"; ?> |
Installed Size: | not found in pkg-api")."\n"; ?> |
Build Date: | not found in pkg-api")."\n"; ?> |
Last Updated: |