1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-09-17 10:40:12 +02:00

Human readable permission data will now be cached in serialized form for faster page generation.

This commit is contained in:
Hans-Emil Skogh 2012-01-10 19:53:23 +01:00
parent bb23e7fd4c
commit 88196e8b9b
2 changed files with 36 additions and 3 deletions

View File

@ -4,9 +4,37 @@ $android_manifest_file_path = 'AndroidManifest.xml';
// Path to the strings.xml-file from the Android source. Get it from https://raw.github.com/android/platform_frameworks_base/master/core/res/res/values/strings.xml for example.
$android_strings_file_path = 'strings.xml';
// Returns an associative array with android permissions and data about them
function get_android_permissions_array($android_manifest_file_path, $android_strings_file_path) {
$cache_file_path = 'android-permissions.cache';
// Returns an associative array with android permissions and data about them
function get_android_permissions_array($android_manifest_file_path, $android_strings_file_path, $cache_file_path) {
// Check status of cache
$android_manifest_file_stat = stat($android_manifest_file_path);
$android_manifest_file_mtime = $android_manifest_file_stat['mtime'];
$android_strings_file_stat = stat($android_strings_file_path);
$android_strings_file_mtime = $android_strings_file_stat['mtime'];
$cache_file_mtime = 0;
if(file_exists($cache_file_path)) {
$cache_file_stat = stat($cache_file_path);
$cache_file_mtime = $cache_file_stat['mtime'];
}
// If the cache is fresh, use it instead
if($android_manifest_file_mtime < $cache_file_mtime && $android_strings_file_mtime < $cache_file_mtime ) {
$cache_file_handle = fopen($cache_file_path, 'r');
$cache_file_content = fread($cache_file_handle, filesize($cache_file_path));
fclose($cache_file_handle);
$permissions = unserialize($cache_file_content);
return $permissions;
}
// We are updating the cache, touch the file (note: race condition possible between stating the cache file above and this line...)
touch($cache_file_path);
// Get permission raw data from XML
$manifestDoc = new DOMDocument;
$manifestDoc->load($android_manifest_file_path);
$manifestXpath = new DOMXPath($manifestDoc);
@ -64,6 +92,11 @@ function get_android_permissions_array($android_manifest_file_path, $android_str
$comment = '';
}
}
// Update cache with serialized permissions
$cache_file_handle = fopen($cache_file_path, 'w');
fwrite($cache_file_handle, serialize($permissions));
fclose($cache_file_handle);
return $permissions;
}

View File

@ -103,7 +103,7 @@ class FDroid
function get_app($query_vars) {
$permissions_data = get_android_permissions_array($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml');
$permissions_data = get_android_permissions_array($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');
$xml = simplexml_load_file($this->site_path.'/repo/index.xml');
foreach($xml->children() as $app) {