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
 
  12 $_MIRROR = 'https://ftp5.gwdg.de/pub/misc/openstreetmap/planet.openstreetmap.org/';
 
  16                           'FOLDER'     => '<%= node[:planet][:dump][:xml_directory] %>/'.$_YEAR.'/',
 
  17                           'REGEX'      => '/^(planet|changesets|discussions)\-\d{6}(\-nolt)?\.osm\.(bz2|gz)$/',
 
  18                           'DIR_PREFIX' => 'planet/'.$_YEAR.'/'
 
  22                           'FOLDER' => '<%= node[:planet][:dump][:xml_history_directory] %>/'.$_YEAR.'/',
 
  23                           'REGEX'  => '/^(history)\-\d{6}(\-nolt)?\.osm\.(bz2|gz)$/',
 
  24                           'DIR_PREFIX' => 'planet/full-history/'.$_YEAR.'/'
 
  27                           'FOLDER'     => '<%= node[:planet][:dump][:pbf_directory] %>/',
 
  28                           'REGEX'      => '/^(planet)\-\d{6}(\-nolt)?\.osm\.pbf$/',
 
  29                           'DIR_PREFIX' => 'pbf/'
 
  33                           'FOLDER' => '<%= node[:planet][:dump][:pbf_history_directory] %>/',
 
  34                           'REGEX'  => '/^(history)\-\d{6}(\-nolt)?\.osm\.pbf$/',
 
  35                           'DIR_PREFIX' => 'pbf/full-history/'
 
  39 $_PLANET_HTACCESS = realpath('<%= node[:planet][:dump][:xml_directory] %>/..').'/.htaccess';
 
  41 function _MIRROR_FILE_SIZE($url) {
 
  43         curl_setopt($ch, CURLOPT_URL, $url);
 
  44         curl_setopt($ch, CURLOPT_NOBODY, TRUE);
 
  45         curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
 
  46         $curl_response = @curl_exec($ch);
 
  47         $curl_result = curl_getinfo($ch);
 
  48         if ($curl_result['http_code']!='200') return FALSE;
 
  49         return ($curl_result['download_content_length']);
 
  52 if (!is_writable($_PLANET_HTACCESS)) die('File '.$_PLANET_HTACCESS.' is not writable by current user.'."\n");
 
  54 $htaccess_contents = file_get_contents($_PLANET_HTACCESS);
 
  55 $htaccess_handle = fopen($_PLANET_HTACCESS, 'a');
 
  57 foreach ($_FOLDERS as $FOLDER) {
 
  59   $_PLANET_FOLDER = $FOLDER["FOLDER"];
 
  60   $_PLANET_REGEX  = $FOLDER["REGEX"];
 
  62   if (!(is_dir($_PLANET_FOLDER))) {
 
  66   if ($dh = opendir($_PLANET_FOLDER)) {
 
  67     while (($file = readdir($dh)) !== false ) {
 
  68       if (preg_match($_PLANET_REGEX, $file)) {
 
  69         $file_slashed = str_replace(array('.','-'), array('\.','\-'), $FOLDER['DIR_PREFIX'].$file);
 
  70         if (strpos($htaccess_contents, $file_slashed) === false) {
 
  71           $file_size = filesize($_PLANET_FOLDER.$file);
 
  73           $file_mirror_size = _MIRROR_FILE_SIZE($_MIRROR.$FOLDER['DIR_PREFIX'].$file);
 
  74           if ($file_size==$file_mirror_size) {
 
  75             echo 'Adding: '.$file."\n";
 
  76             fwrite($htaccess_handle, 'RewriteRule'."\t". '^('.$file_slashed.')$'."\t".$_MIRROR.'$1'."\t".'[R,L]'."\n");
 
  85 fclose($htaccess_handle);