lib/extension.rb in narou-2.9.5 vs lib/extension.rb in narou-3.0.0

- old
+ new

@@ -16,10 +16,23 @@ # ファイル書き込み中のPCクラッシュ等でデータが飛ばない様にする # require "securerandom" def File.write(path, string, *options) - dirname = File.dirname(path) - temp_path = File.join(dirname, SecureRandom.hex(15)) + dirpath = File.dirname(path) + backup = false + temp_path = + if File.extname(path) == ".yaml" && File.basename(dirpath) != Downloader::SECTION_SAVE_DIR_NAME + backup = true + "#{path}.backup" + else + File.join(dirpath, SecureRandom.hex(15)) + end + super(temp_path, string, *options) - File.rename(temp_path, path) + + if backup + super(path, string, *options) + else + File.rename(temp_path, path) + end end