YUKI Hiroshi
null+****@clear*****
Tue May 27 17:10:02 JST 2014
YUKI Hiroshi 2014-05-27 17:10:02 +0900 (Tue, 27 May 2014) New Revision: 78aa9077e9b0f3c0660ce32486178c9632c61271 https://github.com/droonga/droonga-engine/commit/78aa9077e9b0f3c0660ce32486178c9632c61271 Message: Generate catalog.json safely Modified files: bin/droonga-engine-catalog-generate Modified: bin/droonga-engine-catalog-generate (+7 -1) =================================================================== --- bin/droonga-engine-catalog-generate 2014-05-27 16:08:19 +0900 (4b74365) +++ bin/droonga-engine-catalog-generate 2014-05-27 17:10:02 +0900 (5340c90) @@ -18,6 +18,8 @@ require "ostruct" require "optparse" require "json" +require "tempfile" +require "pathname" require "droonga/engine/version" require "droonga/catalog_generator" @@ -97,9 +99,13 @@ def open_output(path) if path == "-" yield($stdout) else - File.open(path, "w") do |output| + # Don't output the file directly to prevent loading of incomplete file! + path = Pathname(path) + temp_file = Tempfile.new(path.basename.to_s, path.parent.to_s) + File.open(temp_file, "w") do |output| yield(output) end + File.rename(temp_file.path, path.to_s) end end -------------- next part -------------- HTML����������������������������...Download