summaryrefslogtreecommitdiff
path: root/tool/lib
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-12-13 00:15:02 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2022-12-13 00:17:47 -0800
commit5ba9dcff16226bbe0f24b234e62e2ed67a17ac53 (patch)
treec68a2597687e6c003c3b2965c5a7593b76270359 /tool/lib
parent7edcdc380f3bb6f5a81bfb5798c339acd844a0d3 (diff)
downloadruby-5ba9dcff16226bbe0f24b234e62e2ed67a17ac53.tar.gz
Make sure f.read is not called twice
--revision.h and --if-change are not used simultaneously, but they might be in the future. Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Diffstat (limited to 'tool/lib')
-rw-r--r--tool/lib/output.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/tool/lib/output.rb b/tool/lib/output.rb
index b1c4f4a866..a7faa44810 100644
--- a/tool/lib/output.rb
+++ b/tool/lib/output.rb
@@ -28,8 +28,11 @@ class Output
updated = color.fail("updated")
outpath = nil
- if (@ifchange or overwrite or create_only) and
- (@vpath.open(@path, "rb") {|f| outpath = f.path; (@ifchange and f.read == data) or (create_only and !f.read.empty?)} rescue false)
+ if (@ifchange or overwrite or create_only) and (@vpath.open(@path, "rb") {|f|
+ outpath = f.path
+ original = f.read
+ (@ifchange and original == data) or (create_only and !original.empty?)
+ } rescue false)
puts "#{outpath} #{unchanged}"
written = false
else