]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/tile/files/default/ruby/expire.rb
Fix simple-mmap require
[chef.git] / cookbooks / tile / files / default / ruby / expire.rb
index c6916943ade718c8c0840be36a0549aeb88e348b..1d4a861f4e193dc6cc8e1563007626c1e4c9c724 100755 (executable)
@@ -1,11 +1,11 @@
 #!/usr/bin/ruby
 
-require 'rubygems'
-require 'proj4'
-require 'xml/libxml'
-require 'set'
-require 'time'
-require 'mmap'
+require "rubygems"
+require "proj4"
+require "xml/libxml"
+require "set"
+require "time"
+require "simple_mmap"
 
 module Expire
   # projection object to go from latlon -> spherical mercator
@@ -50,8 +50,8 @@ module Expire
     # generate the path
     hash_path = (0..4).collect do |i|
       (((x >> 4 * i) & 0xf) << 4) | ((y >> 4 * i) & 0xf)
-    end.reverse.join('/')
-    z.to_s + '/' + hash_path + ".meta"
+    end.reverse.join("/")
+    z.to_s + "/" + hash_path + ".meta"
   end
 
   # time to reset to, some very stupidly early time, before OSM started
@@ -102,17 +102,17 @@ module Expire
 
     # we put all the nodes into the hash, as it doesn't matter whether the node was
     # added, deleted or modified - the tile will need updating anyway.
-    doc.find('//node').each do |node|
-      lat = node['lat'].to_f
+    doc.find("//node").each do |node|
+      lat = node["lat"].to_f
       if lat < -85
         lat = -85
       end
       if lat > 85
         lat = 85
       end
-      point = Proj4::Point.new(Math::PI * node['lon'].to_f / 180,
+      point = Proj4::Point.new(Math::PI * node["lon"].to_f / 180,
                                Math::PI * lat / 180)
-      nodes[node['id'].to_i] = tile_from_latlon(point, max_zoom)
+      nodes[node["id"].to_i] = tile_from_latlon(point, max_zoom)
     end
 
     # now we look for all the ways that have changed and put all of their nodes into
@@ -124,15 +124,16 @@ module Expire
     # itself deleted and the coverage of the point set isn't enough to encompass the
     # change.
     node_cache = NodeCache.new(NODE_CACHE_FILE)
-    doc.find('//way/nd').each do |node|
-      node_id = node['ref'].to_i
-      unless nodes.include? node_id
-        # this is a node referenced but not added, modified or deleted, so it should
-        # still be in the node cache.
-        if entry = node_cache[node_id]
-          point = Proj4::Point.new(entry.lon, entry.lat)
-          nodes[node_id] = tile_from_merc(point, max_zoom)
-        end
+    doc.find("//way/nd").each do |node|
+      node_id = node["ref"].to_i
+
+      next if nodes.include? node_id
+
+      # this is a node referenced but not added, modified or deleted, so it should
+      # still be in the node cache.
+      if (entry = node_cache[node_id])
+        point = Proj4::Point.new(entry.lon, entry.lat)
+        nodes[node_id] = tile_from_merc(point, max_zoom)
       end
     end
 
@@ -163,7 +164,7 @@ module Expire
 
     # open the cache
     def initialize(filename)
-      @cache = Mmap.new(filename)
+      @cache = SimpleMmap::FileWindow.open(filename)
 
       throw "Unexpected format" unless @cache[0..3].unpack("l").first == 1
       throw "Unexpected ID size" unless @cache[4..7].unpack("l").first == 8