Detect when a .do script deletes its stdout tmp file.

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.
This commit is contained in:
Avery Pennarun 2018-12-12 03:36:09 +00:00
commit 1f79bf1174
5 changed files with 43 additions and 3 deletions

View file

@ -1 +1,2 @@
deltest2
/destruct

View file

@ -1 +1 @@
redo deltest deltest2
redo deltest deltest2 deltest3

View file

@ -1 +1,2 @@
rm -rf destruct
rm -f deltest2 *~ .*~

25
t/202-del/deltest3.do Normal file
View file

@ -0,0 +1,25 @@
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