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 = 'https://ftp.heanet.ie/mirrors/openstreetmap.org/planet/'.$_YEAR.'/';
14 $_PLANET_HTACCESS = realpath('<%= node[:planet][:dump][:xml_directory] %>/..').'/.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 $file_size = filesize($_PLANET_FOLDER.$file);
39 $file_mirror_size = _MIRROR_FILE_SIZE($_MIRROR.$file);
40 if ($file_size==$file_mirror_size) {
41 echo 'Adding: '.$file."\n";
42 fwrite($htaccess_handle, 'RewriteRule'."\t".
43 '^('.$file_slashed.')$'."\t".
44 'https://ftp.heanet.ie/mirrors/openstreetmap.org/$1'."\t".
51 fclose($htaccess_handle);