Verified Commit 06ce2f09 authored by noplanman's avatar noplanman

Move fetching and saving binary files to separate functions.

parent 158f8293
......@@ -21,6 +21,34 @@ function get_bintray_files_cache($force = false)
return json_decode($files_json, false);
}
function get_binary_files()
{
$files = [];
foreach (get_bintray_files_cache() as $file) {
$files[$file->name] = $file;
}
uasort($files, static function ($a, $b) {
return version_compare($b->version, $a->version);
});
return $files;
}
function save_binaries_json($files, $version)
{
$binaries = [];
foreach (['armv5', 'armv6', 'arm64'] as $flavor) {
$binary = "borg-{$version}-{$flavor}";
$binaries[$flavor] = [
'version' => $files[$binary]->version,
'size' => $files[$binary]->size,
'sha256' => $files[$binary]->sha256,
'url' => get_dl_link($flavor, $version),
];
}
file_put_contents('binaries.json', json_encode($binaries));
}
function human_filesize($bytes, $decimals = 2)
{
$sz = 'BKMGTP';
......@@ -41,28 +69,14 @@ function get_dl_link($flavor, $version, $file = null)
return "{$base}/borg-{$version}-{$flavor}";
}
$files = [];
foreach (get_bintray_files_cache() as $file) {
$files[$file->name] = $file;
}
uasort($files, static function ($a, $b) {
return version_compare($b->version, $a->version);
});
// Fetch the clean list of binary files.
$files = get_binary_files();
// Get the latest version number.
$stable = reset($files)->version;
$binaries = [];
foreach (['armv5', 'armv6', 'arm64'] as $flavor) {
$binary = "borg-{$stable}-{$flavor}";
$binaries[$flavor] = [
'version' => $files[$binary]->version,
'size' => $files[$binary]->size,
'sha256' => $files[$binary]->sha256,
'url' => get_dl_link($flavor, $stable),
];
}
file_put_contents('binaries.json', json_encode($binaries));
// Save binary details of latest stable version to "binaries.json".
save_binaries_json($files, $stable);
?>
<!DOCTYPE html>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment