[前][次][番号順一覧][スレッド一覧]

ruby-changes:72850

From: Nobuyoshi <ko1@a...>
Date: Sun, 7 Aug 2022 18:25:32 +0900 (JST)
Subject: [ruby-changes:72850] e5e6b87e26 (master): Create temporary file exclusively and clean

https://git.ruby-lang.org/ruby.git/commit/?id=e5e6b87e26

From e5e6b87e265b95620821f7abac56b5ab90d4c1fd Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 6 Aug 2022 20:56:23 +0900
Subject: Create temporary file exclusively and clean

---
 ext/extmk.rb | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ext/extmk.rb b/ext/extmk.rb
index 1624ec9099..40fc10ea1c 100755
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -66,12 +66,17 @@ end https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L66
 
 def atomic_write_open(filename)
   filename_new = filename + ".new.#$$"
-  open(filename_new, "wb") do |f|
+  clean = false
+  File.open(filename_new, "wbx") do |f|
+    clean = true
     yield f
   end
   if File.binread(filename_new) != (File.binread(filename) rescue nil)
     File.rename(filename_new, filename)
-  else
+    clean = false
+  end
+ensure
+  if clean
     File.unlink(filename_new)
   end
 end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]