www/adium.im 423:f383d80b87a2: Multi-Nightly Support

commits at adium.im commits at adium.im
Wed Jul 27 09:29:19 UTC 2011


details:	http://hg.adium.im/www/adium.im/rev/f383d80b87a2
revision:	423:f383d80b87a2
branch:		adiumx.com
author:		Adrian Godoroja <robotive at me.com>
date:		Wed Jul 27 11:52:17 2011 +0300

Multi-Nightly Support

diffs (147 lines):

diff -r b7d9f8678e48 -r f383d80b87a2 sparkle/appcast-nightly.php
--- a/sparkle/appcast-nightly.php	Wed Jul 20 20:40:42 2011 -0500
+++ b/sparkle/appcast-nightly.php	Wed Jul 27 11:52:17 2011 +0300
@@ -1,41 +1,84 @@
 <?php
-	// The nightly host.
-	define("NIGHTLY_HOST", "nightly.adium.im");
-	// The remote file name which contains the current build's information.
-	define("NIGHTLY_REMOTE_NAME", "latest.info");
-	// The location to cache the remote file.
-	define("NIGHTLY_CACHE", $config["cachedgraphs"] . "/nightly-cache.dat");
-	// The interval in seconds to check the remote file.
-	define("UPDATE_INTERVAL", 60*15);
+    function sane_path($path, $default) {
+        if (!isset($path) || preg_match("/\.\.|\/|<|>/", $path)) {
+            return $default;
+        } else {
+            return $path;
+        }
+    }
+    
+    function existing_branch($repo, $branch) {
+        if (is404($repo, $branch)) {
+            $branch = "default";
+            if (is404($repo, $branch)) {
+                $repo = "adium";
+            }
+        }
+        return array($repo, $branch); 
+    }
+    
+    function is404($repo, $branch) {
+        $url = sprintf("http://%s/$repo-$branch/", NIGHTLY_DOMAIN);
+        $url_cache = $config["cachedgraphs"] . "/url_cache/$repo-$branch.dat";
+        $result = "404 Not Found";
+        
+        if ((!is_file($url_cache) || (($stat = stat(url_cache)) && ($stat[10]+UPDATE_INTERVAL <= time())))) {
+            $c = curl_init($url);
+            curl_setopt($c, CURLOPT_NOBODY, TRUE);
+            curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
+            $result = curl_exec($c);
+            curl_close($c);
+            @file_put_contents($url_cache, $result);
+        } else {
+            $result = @file_get_contents($url_cache);
+        }
+        return (strpos($result, "404 Not Found") !== FALSE);
+    }
+    
+    // The nightly domain.
+    define("NIGHTLY_DOMAIN", "nightly.adium.im");        
+    // The remote file name which contains the current build's information.
+    define("NIGHTLY_REMOTE_NAME", "latest.info");
+    // The interval in seconds to check the remote file.
+    define("UPDATE_INTERVAL", 60*15);
+    
+    $repo = sane_path($_GET['repo'], 'adium');
+    $branch = sane_path($_GET['branch'], 'default');
+    list($repo, $branch) = existing_branch($repo, $branch);
+    $repo_branch = "$repo-$branch";
 
-	// Offsets by line in the build file:
-	define("FILENAME", 0);
-	define("REVISION", 1);
-	define("MD5", 2);
-	define("SIZE", 3);
-	define("VERSION", 4);
-	define("DSA", 5);
-	
-	// Update from the remote file if it's out of date or nonexistant.
-	if ((!is_file(NIGHTLY_CACHE) || (($stat = stat(NIGHTLY_CACHE)) && ($stat[10]+UPDATE_INTERVAL <= time())))) {
-		// @ the command in case it fails; if it fails, we don't want to break the xml.
-		$contents = @file_get_contents(sprintf("http://%s/%s", NIGHTLY_HOST, NIGHTLY_REMOTE_NAME));
-		
-		// Don't push nothing in.
-		if ($contents) {
-			@file_put_contents(NIGHTLY_CACHE, $contents);
-		}
-	}
-	
-	// file() keeps the newlines, we don't want them. Instead, use file_get_contents and explode it.
-	$nightlyData = explode("\n", file_get_contents(NIGHTLY_CACHE));
+    // The nightly host.
+    define("NIGHTLY_HOST", sprintf("%s/$repo_branch/", NIGHTLY_DOMAIN));
+    // The location to cache the remote file.
+    define("NIGHTLY_CACHE", $config["cachedgraphs"] . "/nightly-$repo_branch-cache.dat");
 
-	// The address to download the nightly.
-	$nightlyURL = sprintf("http://%s/%s.dmg", NIGHTLY_HOST, $nightlyData[FILENAME]);
-	
-	// The address for the changelog.
-	$tracURL = sprintf("http://hg.adium.im/adium/log?rev=%s",
-					str_replace("r", "", $nightlyData[REVISION]));
+    // Offsets by line in the build file:
+    define("FILENAME", 0);
+    define("REVISION", 1);
+    define("MD5", 2);
+    define("SIZE", 3);
+    define("VERSION", 4);
+    define("DSA", 5);
+    
+    // Update from the remote file if it's out of date or nonexistant.
+    if ((!is_file(NIGHTLY_CACHE) || (($stat = stat(NIGHTLY_CACHE)) && ($stat[10]+UPDATE_INTERVAL <= time())))) {
+        // @ the command in case it fails; if it fails, we don't want to break the xml.
+        $contents = @file_get_contents(sprintf("http://%s/%s", NIGHTLY_HOST, NIGHTLY_REMOTE_NAME));
+        
+        // Don't push nothing in.
+        if ($contents) {
+            @file_put_contents(NIGHTLY_CACHE, $contents);
+        }
+    }
+    
+    // file() keeps the newlines, we don't want them. Instead, use file_get_contents and explode it.
+    $nightlyData = explode("\n", file_get_contents(NIGHTLY_CACHE));
+
+    // The address to download the nightly.
+    $nightlyURL = sprintf("http://%s/%s.dmg", NIGHTLY_HOST, $nightlyData[FILENAME]);
+    
+    // The address for the changelog.
+    $tracURL = sprintf("http://hg.adium.im/$repo/log?rev=%s", str_replace("r", "", $nightlyData[REVISION]));
 
 ?><?php echo('<?');?>xml version="1.0" encoding="UTF-8"?>
 <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
@@ -46,14 +89,14 @@
         <title><?=$nightlyData[FILENAME]?></title>
         <pubDate></pubDate>
         <sparkle:releaseNotesLink><?=$tracURL?></sparkle:releaseNotesLink> 
-        <sparkle:minimumSystemVersion>10.6</sparkle:minimumSystemVersion>
+        <sparkle:minimumSystemVersion><?=($repo == 'adium-1.4') ? '10.5.8' : '10.6'?></sparkle:minimumSystemVersion>
         <enclosure
-			sparkle:dsaSignature="<?=$nightlyData[DSA]?>"
-			sparkle:md5Sum="<?=$nightlyData[MD5]?>"
-			sparkle:version="<?=$nightlyData[VERSION]?>"
-			url="<?=$nightlyURL?>"
-			length="<?=$nightlyData[SIZE]?>"
-			type="application/octet-stream" />
+            sparkle:dsaSignature="<?=$nightlyData[DSA]?>"
+            sparkle:md5Sum="<?=$nightlyData[MD5]?>"
+            sparkle:version="<?=$nightlyData[VERSION]?>"
+            url="<?=$nightlyURL?>"
+            length="<?=$nightlyData[SIZE]?>"
+            type="application/octet-stream" />
     </item>
   </channel>
-</rss>
+</rss>
\ No newline at end of file




More information about the commits mailing list