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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-11-03 12:40:24 +00:00
parent ddf1d3aaed
commit bcfb4569aa
2 changed files with 16 additions and 4 deletions

View File

@ -4,6 +4,7 @@
set -e set -e
timestamp= timestamp=
keepsuffix= keepsuffix=
empty=
until [ $# -eq 0 ]; do until [ $# -eq 0 ]; do
case "$1" in case "$1" in
--timestamp) --timestamp)
@ -18,6 +19,9 @@ until [ $# -eq 0 ]; do
--keep=*) --keep=*)
keepsuffix=`expr \( "$1" : '[^=]*=\(.*\)' \)` keepsuffix=`expr \( "$1" : '[^=]*=\(.*\)' \)`
;; ;;
--empty)
empty=yes
;;
*) *)
break break
;; ;;
@ -33,7 +37,7 @@ if [ "$temp" = - ]; then
trap 'rm -f "$temp"' 0 trap 'rm -f "$temp"' 0
fi 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" echo "$target unchanged"
rm -f "$temp" rm -f "$temp"
else else

View File

@ -3,6 +3,7 @@
set timestamp= set timestamp=
set keepsuffix= set keepsuffix=
set empty=
:optloop :optloop
for %%I in (%1) do set opt=%%~I for %%I in (%1) do set opt=%%~I
if "%opt%" == "--timestamp" ( if "%opt%" == "--timestamp" (
@ -21,6 +22,10 @@ if "%opt%" == "--timestamp" (
set keepsuffix=%opt:~7% set keepsuffix=%opt:~7%
shift shift
goto :optloop goto :optloop
) else if "%opt%" == "--empty" (
set empty=yes
shift
goto :optloop
) )
if "%opt%" == "" goto :end if "%opt%" == "" goto :end
@ -66,15 +71,18 @@ del %2
goto :end goto :end
:nt :nt
if not exist %src% goto :end
if exist %dest% ( 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 && ( fc.exe %dest% %src% > nul && (
echo %1 unchanged. :nt_unchanged
del %src% del %src%
:nt_unchanged1
for %%I in (%1) do echo %%~I unchanged
goto :nt_end goto :nt_end
) )
) )
echo %1 updated. for %%I in (%1) do echo %%~I updated
copy %src% %dest% > nul copy %src% %dest% > nul
del %src% del %src%