# # # patch "downloads.php" # from [24ae2a1bc46378a172b9540f0ea957435206536e] # to [a2a7c55e8d426804a8b5faf87060156c353623f6] # ============================================================ --- downloads.php 24ae2a1bc46378a172b9540f0ea957435206536e +++ downloads.php a2a7c55e8d426804a8b5faf87060156c353623f6 @@ -1,27 +1,28 @@ "/monotone-%version%\.tar\.gz/", "Linux x86/glibc 2.3" => "/mtn-%version%-linux-x86\.bz2/", + "Windows Installer" => "/monotone-%version%-setup\.exe/", "Mac OS X Installer" => "/monotone-%version%\.dmg/", "Mac OS X Binary" => "/mtn-%version%-osx(-univ)?\.bz2/", "Solaris Package" => "/PMmonotone-%version%\.(i386|sparc)\.pkg/", - "Windows Installer" => "/monotone-%version%-setup\.exe/", ); -$webdir = "/downloads"; -$basedir = dirname(__FILE__) . "/downloads"; -$releaseDirs = scandir($basedir, 1); +$webdir = "/downloads"; +$basedir = dirname(__FILE__) . "/downloads"; +$cachedir = "/data/monotone.ca/cache"; +$releaseDirs = scandir($basedir, 1); function getLatestFiles() { global $matchers, $webdir, $basedir, $releaseDirs; $latestFiles = array(); - $matchedPlatforms = array(); + $matchedTypes = array(); foreach ($releaseDirs as $dir) { @@ -29,40 +30,40 @@ function getLatestFiles() continue; // a little optimization - if (count($matchedPlatforms) == count($matchers)) + if (count($matchedTypes) == count($matchers)) break; $files = scandir("$basedir/$dir", 1); $release = $dir; - $newlyMatchedPlatforms = array(); + $newlyMatchedTypes = array(); foreach ($files as $file) { - foreach ($matchers as $platform => $matcher) + foreach ($matchers as $type => $matcher) { if (preg_match(str_replace("%version%", $release, $matcher), $file) && - !in_array($platform, $matchedPlatforms)) + !in_array($type, $matchedTypes)) { - if (!isset($latestFiles[$platform])) + if (!isset($latestFiles[$type])) { - $latestFiles[$platform] = array(); + $latestFiles[$type] = array(); } - $latestFiles[$platform][] = "$release/$file"; - $newlyMatchedPlatforms[] = $platform; + $latestFiles[$type][] = "$release/$file"; + $newlyMatchedTypes[] = $type; } } } - $matchedPlatforms = array_merge($matchedPlatforms, $newlyMatchedPlatforms); + $matchedTypes = array_merge($matchedTypes, $newlyMatchedTypes); } return $latestFiles; } -function getAllFiles($platform) +function getAllFiles($type) { global $matchers, $webdir, $basedir, $releaseDirs; - $matcher = $matchers[$platform]; + $matcher = $matchers[$type]; $allFiles = array(); foreach ($releaseDirs as $dir) @@ -86,21 +87,61 @@ function getAllFiles($platform) return $allFiles; } +class cache +{ + private static $instance; + private $basedir; + private $cachedir; + private $cache = array(); + private function __construct($basedir, $cachedir) + { + $this->basedir = $basedir; + $this->cachedir = $cachedir; + if (is_file("$cachedir/download_cache")) + $this->cache = (array)@unserialize( + file_get_contents("$cachedir/download_cache") + ); + } + public function __destruct() + { + if (is_writable($this->cachedir)) + file_put_contents("{$this->cachedir}/download_cache", + serialize($this->cache)); + } + public function get($file) + { + if (!isset($this->cache[$file])) + { + $this->cache[$file] = array( + filesize("{$this->basedir}/$file"), + sha1_file("{$this->basedir}/$file") + ); + } + return $this->cache[$file]; + } + public static function instance($basedir, $cachedir) + { + if (!self::$instance) + self::$instance = new cache($basedir, $cachedir); + return self::$instance; + } +} + $page_title = "Downloads"; require_once("header.inc.php"); ?>
-

Latest monotone downloads by platform

+

Latest monotone downloads by type

No files found

$files): - if (!is_array($files)) - continue; + foreach (array_keys($matchers) as $type): + if (!is_array($latestFiles[$type])) + continue; echo<<$platform +
$type
END; - foreach ($files as $file): + foreach ($latestFiles[$type] as $file): $name = basename($file); $release = dirname($file); - $size = round(filesize("$basedir/$file") / (1024*1024), 2)."MB"; - $sha1 = sha1_file("$basedir/$file"); + list($size, $sha1) = cache::instance($basedir, $cachedir)->get($file); + $size = round($size / (1024*1024), 2)."MB"; echo << $name ($size, SHA1 $sha1)
- » all packages for this platform + » all downloads of this type END; endforeach; @@ -132,19 +173,19 @@ else:

No files found

$platform +
$type
END; foreach ($allFiles as $file): $name = basename($file); $release = dirname($file); - $size = round(filesize("$basedir/$file") / (1024*1024), 2)."MB"; - $sha1 = sha1_file("$basedir/$file"); + list($size, $sha1) = cache::instance($basedir, $cachedir)->get($file); + $size = round($size / (1024*1024), 2)."MB"; echo << $name ($size, SHA1 $sha1)