anchor.diff:        aws s3 rm ${1}$(echo ${record} | awk '{print $4}')
       fi
     done
  +}
  +
  +function get_latest_transit() {
  +  latest=0
  +  latest_upload=""
  +  files=$(aws s3 ls ${1}transit_)
  +  while read record; do
  +    added=$(date -d "$(echo ${record} | awk '{print $1" "$2}')" +%s)
  +    if [[ ${added} -gt ${latest} ]]; then
  +      latest=${added}
  +      latest_upload=${1}$(echo ${record} | awk '{print $4}')
  +    fi
  +  done <<< "$files"
  +
  +  aws s3 cp $latest_upload <%= node[:valhalla][:transit_dir] %>_latest.tgz
  +
  +  #if first run, use the latest.
  +  if [ ! -f <%= node[:valhalla][:transit_dir] %>.tgz ]; then
  +    mv <%= node[:valhalla][:transit_dir] %>_latest.tgz <%= node[:valhalla][:transit_dir] %>.tgz
  +  else
  +    latest=$(md5sum <%= node[:valhalla][:transit_dir] %>_latest.tgz)
  +    in_use=$(md5sum <%= node[:valhalla][:transit_dir] %>.tgz)
  +
  +    # new version has been uploaded.
  +    if [ "$latest" -ne "$in_use" ]; then
  +      mv <%= node[:valhalla][:transit_dir] %>_latest.tgz <%= node[:valhalla][:transit_dir] %>.tgz
  +
  +      rm -rf <%= node[:valhalla][:transit_dir] %>
  +      mkdir <%= node[:valhalla][:transit_dir] %>
  +      tar pxf <%= node[:valhalla][:transit_dir] %>.tgz -C <%= node[:valhalla][:transit_dir] %>
  +    else
  +      rm <%= node[:valhalla][:transit_dir] %>_latest.tgz
  +    fi
  +  fi
   }
   
   function fail() {
  
positive.code: fi
  
  #transit data
  if [ -f <%= node[:valhalla][:transit_dir] %>.tgz ]; then
    rm -rf <%= node[:valhalla][:transit_dir] %>
    mkdir <%= node[:valhalla][:transit_dir] %>
    tar pxf <%= node[:valhalla][:transit_dir] %>.tgz -C <%= node[:valhalla][:transit_dir] %>
  fi
  
  # cut tiles from the data
  valhalla_build_tiles -c <%= node[:valhalla][:config] %> $(find <%= node[:valhalla][:extracts_dir] %> -type f -name "*.pbf")
  
negative.code: for f in connectivity*; do  mv_stamp $f ${stamp}; done
  mv_stamp statistics.sqlite ${stamp}
  mv_stamp maproulette_tasks.geojson ${stamp}
  cp_stamp ${tile_dir}/$(basename ${admin_file}) ${stamp}
  cp_stamp ${tile_dir}/$(basename ${timezone_file}) ${stamp}
  pushd ${tile_dir}
  