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>
This commit is contained in:
Takashi Kokubun 2022-12-13 00:15:02 -08:00
parent 7edcdc380f
commit 5ba9dcff16
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

View File

@ -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