[Groonga-commit] droonga/droonga-engine at 11202b6 [master] Output live-nodes.json safely

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue May 27 17:20:30 JST 2014


YUKI Hiroshi	2014-05-27 17:20:30 +0900 (Tue, 27 May 2014)

  New Revision: 11202b608900d109cd68df765a9e30c9abff0af6
  https://github.com/droonga/droonga-engine/commit/11202b608900d109cd68df765a9e30c9abff0af6

  Message:
    Output live-nodes.json safely

  Modified files:
    lib/droonga/command/serf_event_handler.rb

  Modified: lib/droonga/command/serf_event_handler.rb (+6 -3)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-05-27 17:19:01 +0900 (890844d)
+++ lib/droonga/command/serf_event_handler.rb    2014-05-27 17:20:30 +0900 (b17750a)
@@ -17,6 +17,7 @@ require "optparse"
 require "pathname"
 require "json"
 require "fileutils"
+require "tempfile"
 
 require "droonga/path"
 require "droonga/serf"
@@ -72,10 +73,12 @@ module Droonga
         list_path = LiveNodesListObserver.path
         nodes = live_nodes
         file_contents = JSON.pretty_generate(nodes)
-        FileUtils.mkdir_p(list_path.parent.to_s)
-        list_path.open("w") do |file|
-          file.write(file_contents)
+        # Don't output the file directly to prevent loading of incomplete file!
+        temp_file = Tempfile.open(list_path.basename.to_s, list_path.parent.to_s, "w") do |output|
+          output.write(file_contents)
+          output.path
         end
+        File.rename(temp_file, list_path.to_s)
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index