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

ruby-changes:4329

From: ko1@a...
Date: Fri, 21 Mar 2008 09:25:42 +0900 (JST)
Subject: [ruby-changes:4329] nobu - Ruby:r15819 (ruby_1_8, trunk): * instruby.rb (open_for_install): write block result and rewrite only

nobu	2008-03-21 09:24:30 +0900 (Fri, 21 Mar 2008)

  New Revision: 15819

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/instruby.rb
    branches/ruby_1_8/version.h
    trunk/ChangeLog
    trunk/instruby.rb

  Log:
    * instruby.rb (open_for_install): write block result and rewrite only
      if changed from existing file.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=15819&r2=15818&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15819&r2=15818&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/instruby.rb?r1=15819&r2=15818&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/version.h?r1=15819&r2=15818&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/instruby.rb?r1=15819&r2=15818&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15818)
+++ ChangeLog	(revision 15819)
@@ -1,3 +1,8 @@
+Fri Mar 21 09:24:28 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* instruby.rb (open_for_install): write block result and rewrite only
+	  if changed from existing file.
+
 Fri Mar 21 08:29:33 2008  Tadayoshi Funaba  <tadf@d...>
 
 	* rational.c (nurat_to_f): rearrangement.
Index: instruby.rb
===================================================================
--- instruby.rb	(revision 15818)
+++ instruby.rb	(revision 15819)
@@ -80,7 +80,7 @@
   $mflags.unshift(*mflags)
 
   def $mflags.set?(flag)
-    grep(/\A-(?!-).*#{'%s' % flag}/i) { return true }
+    grep(/\A-(?!-).*#{flag.chr}/i) { return true }
     false
   end
   def $mflags.defined?(var)
@@ -183,9 +183,13 @@
   end
 end
 
-def open_for_install(path, mode, &block)
+def open_for_install(path, mode)
+  data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil
+  newdata = yield
   unless $dryrun
-    open(realpath = with_destdir(path), "wb", mode, &block)
+    unless newdata == data
+      open(realpath, "wb", mode) {|f| f.write newdata}
+    end
     File.chmod(mode, realpath)
   end
   $installed_list.puts path if $installed_list
@@ -290,7 +294,7 @@
   makedirs [bindir, rubylibdir]
 
   ruby_shebang = File.join(bindir, ruby_install_name)
-  if $cmdtype
+  if File::ALT_SEPARATOR
     ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
   end
   for src in Dir["bin/*"]
@@ -311,10 +315,10 @@
 
     cmd = File.join(bindir, name)
     cmd << ".#{$cmdtype}" if $cmdtype
-    open_for_install(cmd, $script_mode) do |f|
+    open_for_install(cmd, $script_mode) do
       case $cmdtype
       when "bat"
-        f.print((<<EOH+shebang+body+<<EOF).gsub(/$/, "\r"))
+        "#{<<EOH}#{shebang}#{body}#{<<EOF}".gsub(/$/, "\r")
 @echo off
 @if not "%~d0" == "~d0" goto WinNT
 #{ruby_bin} -x "#{cmd}" %1 %2 %3 %4 %5 %6 %7 %8 %9
@@ -327,12 +331,12 @@
 :endofruby
 EOF
       when "cmd"
-        f.print(<<EOH, shebang, body)
+        "#{<<EOH}#{shebang}#{body}"
 @"%~dp0#{ruby_install_name}" -x "%~f0" %*
 @exit /b %ERRORLEVEL%
 EOH
       else
-        f.print shebang, body
+        shebang + body
       end
     end
   end
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 15818)
+++ ruby_1_8/ChangeLog	(revision 15819)
@@ -1,3 +1,8 @@
+Fri Mar 21 09:24:28 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* instruby.rb (open_for_install): write block result and rewrite only
+	  if changed from existing file.
+
 Wed Mar 19 21:01:08 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (dir_inspect, dir_path, dir_tell): check for frozen and closed
Index: ruby_1_8/version.h
===================================================================
--- ruby_1_8/version.h	(revision 15818)
+++ ruby_1_8/version.h	(revision 15819)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2008-03-19"
+#define RUBY_RELEASE_DATE "2008-03-21"
 #define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20080319
+#define RUBY_RELEASE_CODE 20080321
 #define RUBY_PATCHLEVEL 5000
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 3
-#define RUBY_RELEASE_DAY 19
+#define RUBY_RELEASE_DAY 21
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8/instruby.rb
===================================================================
--- ruby_1_8/instruby.rb	(revision 15818)
+++ ruby_1_8/instruby.rb	(revision 15819)
@@ -80,7 +80,7 @@
   $mflags.unshift(*mflags)
 
   def $mflags.set?(flag)
-    grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
+    grep(/\A-(?!-).*#{flag.chr}/i) { return true }
     false
   end
   def $mflags.defined?(var)
@@ -183,9 +183,13 @@
   end
 end
 
-def open_for_install(path, mode, &block)
+def open_for_install(path, mode)
+  data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil
+  newdata = yield
   unless $dryrun
-    open(realpath = with_destdir(path), "wb", mode, &block)
+    unless newdata == data
+      open(realpath, "wb", mode) {|f| f.write newdata}
+    end
     File.chmod(mode, realpath)
   end
   $installed_list.puts path if $installed_list
@@ -280,7 +284,7 @@
   makedirs [bindir, rubylibdir]
 
   ruby_shebang = File.join(bindir, ruby_install_name)
-  if $cmdtype
+  if File::ALT_SEPARATOR
     ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
   end
   for src in Dir["bin/*"]
@@ -301,10 +305,10 @@
 
     cmd = File.join(bindir, name)
     cmd << ".#{$cmdtype}" if $cmdtype
-    open_for_install(cmd, $script_mode) do |f|
+    open_for_install(cmd, $script_mode) do
       case $cmdtype
       when "bat"
-        f.print((<<EOH+shebang+body+<<EOF).gsub(/$/, "\r"))
+        "#{<<EOH}#{shebang}#{body}#{<<EOF}".gsub(/$/, "\r")
 @echo off
 @if not "%~d0" == "~d0" goto WinNT
 #{ruby_bin} -x "#{cmd}" %1 %2 %3 %4 %5 %6 %7 %8 %9
@@ -317,12 +321,12 @@
 :endofruby
 EOF
       when "cmd"
-        f.print(<<EOH, shebang, body)
+        "#{<<EOH}#{shebang}#{body}"
 @"%~dp0#{ruby_install_name}" -x "%~f0" %*
 @exit /b %ERRORLEVEL%
 EOH
       else
-        f.print shebang, body
+        shebang + body
       end
     end
   end

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

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