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

ruby-changes:31440

From: nobu <ko1@a...>
Date: Sun, 3 Nov 2013 21:40:28 +0900 (JST)
Subject: [ruby-changes:31440] nobu:r43519 (trunk): ifchange: no overwrite with an empty file

nobu	2013-11-03 21:40:24 +0900 (Sun, 03 Nov 2013)

  New Revision: 43519

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43519

  Log:
    ifchange: no overwrite with an empty file
    
    * tool/ifchange, win32/ifchange.bat: do not overwrite with an empty
      file by default, and add --empty option to force it.

  Modified files:
    trunk/tool/ifchange
    trunk/win32/ifchange.bat
Index: win32/ifchange.bat
===================================================================
--- win32/ifchange.bat	(revision 43518)
+++ win32/ifchange.bat	(revision 43519)
@@ -3,6 +3,7 @@ https://github.com/ruby/ruby/blob/trunk/win32/ifchange.bat#L3
 
 set timestamp=
 set keepsuffix=
+set empty=
 :optloop
 for %%I in (%1) do set opt=%%~I
 if "%opt%" == "--timestamp" (
@@ -21,6 +22,10 @@ if "%opt%" == "--timestamp" ( https://github.com/ruby/ruby/blob/trunk/win32/ifchange.bat#L22
     set keepsuffix=%opt:~7%
     shift
     goto :optloop
+) else if "%opt%" == "--empty" (
+    set empty=yes
+    shift
+    goto :optloop
 )
 if "%opt%" == "" goto :end
 
@@ -66,15 +71,18 @@ del %2 https://github.com/ruby/ruby/blob/trunk/win32/ifchange.bat#L71
 goto :end
 
 :nt
-if not exist %src% goto :end
 if exist %dest% (
+    if not exist %src% goto :nt_unchanged1
+    if "%empty%" == "" for %%I in (%src%) do if %%~zI == 0 goto :nt_unchanged
     fc.exe %dest% %src% > nul && (
-	echo %1 unchanged.
+      :nt_unchanged
 	del %src%
+      :nt_unchanged1
+	for %%I in (%1) do echo %%~I unchanged
 	goto :nt_end
     )
 )
-echo %1 updated.
+for %%I in (%1) do echo %%~I updated
 copy %src% %dest% > nul
 del %src%
 
Index: tool/ifchange
===================================================================
--- tool/ifchange	(revision 43518)
+++ tool/ifchange	(revision 43519)
@@ -4,6 +4,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L4
 set -e
 timestamp=
 keepsuffix=
+empty=
 until [ $# -eq 0 ]; do
     case "$1" in
 	--timestamp)
@@ -18,6 +19,9 @@ until [ $# -eq 0 ]; do https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L19
 	--keep=*)
 	    keepsuffix=`expr \( "$1" : '[^=]*=\(.*\)' \)`
 	    ;;
+	--empty)
+	    empty=yes
+	    ;;
 	*)
 	    break
 	    ;;
@@ -33,7 +37,7 @@ if [ "$temp" = - ]; then https://github.com/ruby/ruby/blob/trunk/tool/ifchange#L37
     trap 'rm -f "$temp"' 0
 fi
 
-if cmp "$target" "$temp" >/dev/null 2>&1; then
+if [ -f "$target" -a ! -${empty:+f}${empty:-s} "$temp" ] || cmp "$target" "$temp" >/dev/null 2>&1; then
     echo "$target unchanged"
     rm -f "$temp"
 else

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

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