summaryrefslogtreecommitdiff
path: root/tool/lib/output.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-02 12:18:17 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-02 12:38:31 +0900
commit3475b661607e6d2c72460ea381ee856726128259 (patch)
treeb002bffcfa967cc1752a5fc91e9c1dee8aa04bfc /tool/lib/output.rb
parentac06951c31c59781951a70788e4b0de2aa3d481c (diff)
downloadruby-3475b661607e6d2c72460ea381ee856726128259.tar.gz
file2lastrev.rb: try to overwrite the found revision.h as before
Diffstat (limited to 'tool/lib/output.rb')
-rw-r--r--tool/lib/output.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/tool/lib/output.rb b/tool/lib/output.rb
index 584be76974..cbaa4b5a3e 100644
--- a/tool/lib/output.rb
+++ b/tool/lib/output.rb
@@ -18,7 +18,7 @@ class Output
@vpath.def_options(opt)
end
- def write(data)
+ def write(data, overwrite: false)
unless @path
$stdout.print data
return true
@@ -26,13 +26,16 @@ class Output
color = Colorize.new(@color)
unchanged = color.pass("unchanged")
updated = color.fail("updated")
+ outpath = nil
- if @ifchange and (@vpath.read(@path, "rb") == data rescue false)
- puts "#{@path} #{unchanged}"
+ if @ifchange and (@vpath.open(@path, "rb") {|f| outpath = f.path; f.read == data} rescue false)
+ puts "#{outpath} #{unchanged}"
written = false
else
- File.binwrite(@path, data)
- puts "#{@path} #{updated}"
+ unless overwrite and outpath and (File.binwrite(outpath, data) rescue nil)
+ File.binwrite(outpath = @path, data)
+ end
+ puts "#{outpath} #{updated}"
written = true
end
if timestamp = @timestamp