4 DO NOT EDIT - This file is being maintained by Chef
7 Check if planet file exists on mirror and link if not yet linked
11 $_PLANET_FOLDER = '<%= node[:planet][:dump][:xml_directory] %>/'.$_YEAR.'/';
12 $_PLANET_REGEX = "/^(planet|changesets)\-\d{6}(\-nolt)?\.osm\.(bz2|gz)$/";
13 $_MIRROR = 'http://ftp.heanet.ie/mirrors/openstreetmap.org/planet/'.$_YEAR.'/';
14 $_PLANET_HTACCESS = realpath($_PLANET_FOLDER.'../..').'/.htaccess';
16 function _MIRROR_FILE_SIZE($url) {
18 curl_setopt($ch, CURLOPT_URL, $url);
19 curl_setopt($ch, CURLOPT_NOBODY, TRUE);
20 curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
21 $curl_response = @curl_exec($ch);
22 $curl_result = curl_getinfo($ch);
23 if ($curl_result['http_code']!='200') return FALSE;
24 return ($curl_result['download_content_length']);
27 if (!is_writable($_PLANET_HTACCESS)) die('File '.$_PLANET_HTACCESS.' is not writable by current user.'."\n");
29 if (is_dir($_PLANET_FOLDER)) {
30 $htaccess_contents = file_get_contents($_PLANET_HTACCESS);
31 $htaccess_handle = fopen($_PLANET_HTACCESS, 'a');
32 if ($dh = opendir($_PLANET_FOLDER)) {
33 while (($file = readdir($dh)) !== false ) {
34 if (preg_match($_PLANET_REGEX,$file)) {
35 $file_slashed = 'planet/'.$_YEAR.'/'.str_replace(array('.','-'), array('\.','\-'), $file);
36 if (strpos($htaccess_contents,$file_slashed) === false) {
37 //PHP IS BRAINDEAD filesize borked >4GB
38 //$file_size = $file_stats['size'];
39 $file_size = trim(`stat -c%s $_PLANET_FOLDER$file`);
41 $file_mirror_size = _MIRROR_FILE_SIZE($_MIRROR.$file);
42 if ($file_size==$file_mirror_size) {
43 echo 'Adding: '.$file."\n";
44 fwrite($htaccess_handle, 'RewriteRule'."\t".
45 '^('.$file_slashed.')$'."\t".
46 'http://ftp.heanet.ie/mirrors/openstreetmap.org/$1'."\t".
53 fclose($htaccess_handle);