@set TEMPPR=%PROMPT%
@if NOT EXIST setup.bat goto ERR1
@echo WARNING: For this test tar.exe MUST be in the PATH ...
@echo as it is run from within genfile ...
@echo Also the test does NOT fully function, since the 'truncate' action,
@echo by 'genfile', done while it runs 'tar' fails with 'invalid handle'
@echo error, due to the use of low level IO 'open', instead of CreateFile(),
@echo but even changing this it still may fail, since the 'foo' is openned by tar
@echo also using the low level IO 'open', and I do NOT think this 'shares' the file,
@echo But the last part of the test, where tar 'diff' is used works fine ...
@pause
call setup
call mdd temp
@if NOT EXIST ..\volume.bat goto ERR2
@set PROMPT=# 

@REM # Tar 1.15.1 incorrectly padded archive members that were truncated during
@REM # archiving.
@REM # References: <1115437005.8530.644529@goedel.fjf.gnu.de>
@REM # http://lists.gnu.org/archive/html/bug-tar/2005-05/msg00008.html
@REM #
@REM # The test case is based on the script by Frank Heckenbach <frank@g-n-u.de>
@REM # Additionally, the test verifies if tar exits with code 1 (file differs).

genfile --file foo --length 50000k
@if NOT EXIST foo goto ERR3
genfile --file baz
genfile --run "tar -vcf bar foo baz" --checkpoint 10 --length 49995k --truncate foo
@echo Exit status: %ERRORLEVEL%
@if NOT EXIST bar goto ERR4

@echo separator
sleep 1
@echo.
@echo Now to truncate file foo
genfile --file foo --seek 49995k --length 5k --pattern=zeros
@echo.
@echo And do a tar --diff ...
%TEMPT% dvf bar
@echo Exit status: %ERRORLEVEL%
@echo Ouput should be ...
@echo foo
@echo foo: Mod time differs
@echo foo: Contents differ
@echo baz
@cd ..
@goto END

:ERR1
@echo Can NOT locate setup.bat ... check name, location ...
@goto END

:ERR2
@echo mdd.bat missing, or failed ... check name, location ...
@goto END

:ERR3
@echo ERROR: genfile failed to create foo ... maybe genfile is not in PATH ...
@goto WAIT

:ERR4
@echo ERROR: The genfile run of tar failed to create archive bar ... maybe tar is not in PATH ...
@echo Or is a different version to %TEMPT% ...
@goto WAIT


:WAIT
cd ..
@set PROMPT=%TEMPPR%
@pause
@goto END

:END
@set PROMPT=%TEMPPR%
