]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/planet/files/default/replication-bin/replicate-changesets
Finish compressed file before syncing it
[chef.git] / cookbooks / planet / files / default / replication-bin / replicate-changesets
index 8fd78a1bc33e1dfee2a81a535d26b24d30290d7e..97cd8a09da2bf6dffd2a551dab1a417d9468fa48 100644 (file)
@@ -18,7 +18,7 @@ GEO_SCALE = 10000000
 ##
 # replace characters which cannot be represented in XML 1.0.
 def xml_sanitize(str)
-  str.gsub(/[\x00-\x08\x0b\x0c\x0e-\x20]/, "?")
+  str.gsub(/[\x00-\x08\x0b\x0c\x0e-\x1f]/, "?")
 end
 
 ##
@@ -188,7 +188,7 @@ class Replicator
       sequence = (@state.key?("sequence") ? @state["sequence"] + 1 : 0)
       data_file = @config["data_dir"] + format("/%03d/%03d/%03d.osm.gz", sequence / 1000000, (sequence / 1000) % 1000, (sequence % 1000))
       tmp_state = @config["state_file"] + ".tmp"
-      tmp_data = "/tmp/changeset_data.osm.tmp"
+      tmp_data = data_file + ".tmp"
       # try and write the files to tmp locations and then
       # move them into place later, to avoid in-progress
       # clashes, or people seeing incomplete files.
@@ -196,18 +196,20 @@ class Replicator
         FileUtils.mkdir_p(File.dirname(data_file))
         Zlib::GzipWriter.open(tmp_data) do |fh|
           fh.write(changeset_dump(open_changesets))
+          fh.finish.fdatasync
         end
         @state["sequence"] = sequence
         File.open(tmp_state, "w") do |fh|
           fh.write(YAML.dump(@state))
+          fh.fdatasync
         end
 
         # sanity check: the files we're moving into place
         # should be non-empty.
-        fail "Temporary gzip file should exist, but doesn't." unless File.exist?(tmp_data)
-        fail "Temporary state file should exist, but doesn't." unless File.exist?(tmp_state)
-        fail "Temporary gzip file should be non-empty, but isn't." if File.zero?(tmp_data)
-        fail "Temporary state file should be non-empty, but isn't." if File.zero?(tmp_state)
+        raise "Temporary gzip file should exist, but doesn't." unless File.exist?(tmp_data)
+        raise "Temporary state file should exist, but doesn't." unless File.exist?(tmp_state)
+        raise "Temporary gzip file should be non-empty, but isn't." if File.zero?(tmp_data)
+        raise "Temporary state file should be non-empty, but isn't." if File.zero?(tmp_state)
 
         FileUtils.mv(tmp_data, data_file)
         FileUtils.mv(tmp_state, @config["state_file"])