summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlo Landmeter <clandmeter@gmail.com>2013-05-11 17:24:13 +0200
committerCarlo Landmeter <clandmeter@gmail.com>2013-05-11 17:24:13 +0200
commit180aac5c8608fe5a981505b22e61859b76dd6e44 (patch)
treec0bdba27bc0473b99987bb03f384cbec3a6a887a
parent462435a44b800d96bd723f436754b02d87bec29e (diff)
downloadapk_browser-180aac5c8608fe5a981505b22e61859b76dd6e44.tar.bz2
apk_browser-180aac5c8608fe5a981505b22e61859b76dd6e44.tar.xz
Convert so names to pkg names in depends
-rw-r--r--apk_browser.module62
1 files changed, 42 insertions, 20 deletions
diff --git a/apk_browser.module b/apk_browser.module
index ec54659..f3e1512 100644
--- a/apk_browser.module
+++ b/apk_browser.module
@@ -398,6 +398,10 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) {
return $node->nid;
}
+/*
+ * take an apk tar string and convert it
+ * to an associative array
+ */
function apk_browser_apkindex_reader($apk_string) {
//file_get_contents outputs string and php tar needs file
$temp = tempnam("/tmp", "apk_");
@@ -406,6 +410,7 @@ function apk_browser_apkindex_reader($apk_string) {
fclose($fp);
$tar_object = new Archive_Tar($temp);
$apkindex = $tar_object->extractInString("APKINDEX");
+ unlink($temp);
//convert packages data into array
$packages = preg_split("`\n\W+`", $apkindex);
//remove last empty line
@@ -413,47 +418,64 @@ function apk_browser_apkindex_reader($apk_string) {
foreach ($packages as $key => $package) {
//convert packages lines into array
$apackage = preg_split("`\n`", $package);
+ $pkg = array();
+ // format the package lines
foreach ($apackage as $apk_line) {
switch ($apk_line[0]) {
- /*
- * Check all package names in install_if depends and provides
- * put them in arrays and remove version/abi numbers.
- * removing version/abi is a bit hackish.
- */
case "D":
case "i":
case "p":
$pkgnames = explode(" ", substr($apk_line, 2));
foreach ($pkgnames as $pkgname) {
$pkgname = explode('=', $pkgname);
- $result[$key][$apk_line[0]][] = $pkgname[0];
+ $pkg[$apk_line[0]][] = $pkgname[0];
}
break;
- //other apk variables
default:
- $result[$key][$apk_line[0]] = substr($apk_line, 2);
+ $pkg[$apk_line[0]] = substr($apk_line, 2);
}
}
- }
- /*
- * this should take care of having multiple packages with different
- * version in repositories
- */
- foreach ($result as $pkg) {
- //check if package name already exit in result array
+ // remove all double packages with lower version number
if (isset($output[$pkg['P']])) {
- //check if version number is higher then previous
if ($output[$pkg['P']]['V'] < $pkg['V']) {
- //if version is higher we overwrite package
$output[$pkg['P']] = $pkg;
}
- //all not matching packages we just write them
} else {
$output[$pkg['P']] = $pkg;
}
}
- unlink($temp);
- return $output;
+ return apk_browser_convert_provides($output);
+}
+
+/*
+ * convert provide so names to package names
+ * remove all duplicated pacakge names upon convert
+ */
+function apk_browser_convert_provides($packages) {
+ // create an associative array of so name and pkg name
+ foreach ($packages as $pkgname => $package) {
+ foreach ($package as $type => $field) {
+ if ($type == 'p') {
+ foreach ($field as $value) {
+ $provides[$value] = $pkgname;
+ }
+ }
+ }
+ }
+ // convert every so name to pkg name
+ foreach ($packages as $pkgname => $package) {
+ foreach ($package as $type => $field) {
+ if ($type == 'D') {
+ foreach ($field as $key => $value) {
+ if (substr($value, 0, 3) === "so:") {
+ $packages[$pkgname][$type][$key] = $provides[$value];
+ }
+ }
+ $packages[$pkgname][$type] = array_values(array_unique($packages[$pkgname][$type]));
+ }
+ }
+ }
+ return $packages;
}
//this is needed for auto views integration