This can happen if we create the .tmp file in the same directory as the target, and the .do file first does "rm -rf" on that directory, then re-creates it. The result is that the stdout file is lost. We'll make this a warning if the .do script *didn't* write to stdout (so the loss is harmless, just weird), and an error if they *did* write to stdout, which we can detect because we still have an open fd on the file, so we can fstat() it.
25 lines
650 B
Text
25 lines
650 B
Text
rm -rf destruct
|
|
mkdir destruct
|
|
cd destruct
|
|
cat >destruct1.do <<-EOF
|
|
rm -f *.tmp
|
|
echo 'redir' >\$3
|
|
EOF
|
|
cat >destruct2.do <<-EOF
|
|
rm -f *.tmp
|
|
echo 'stdout'
|
|
EOF
|
|
|
|
# deleting unused stdout file is a warning only
|
|
redo destruct1 2>destruct1.log || exit 11
|
|
[ "$(cat destruct1)" = "redir" ] || exit 12
|
|
|
|
# deleting *used* stdout file may be a fatal mistake,
|
|
# but we won't enforce that, since some redo variants
|
|
# might be more accepting or use different tmp file
|
|
# algorithms. So either the file should be correct,
|
|
# or it should be missing.
|
|
redo destruct2 2>destruct2.log || :
|
|
if [ -e "destruct2" ]; then
|
|
[ "$(cat destruct2)" = "stdout" ] || exit 22
|
|
fi
|