If the .do script deletes $3, don't die.

This commit is contained in:
Avery Pennarun 2010-11-17 17:55:16 -08:00
commit c7585558ef
5 changed files with 12 additions and 4 deletions

View file

@ -38,7 +38,7 @@ _do()
export DO_DEPTH="$DO_DEPTH "
. "$PWD/$DOFILE" >"$TARGET.tmp"
) &&
mv "$TARGET.tmp" "$TARGET"
mv "$TARGET.tmp" "$TARGET" 2>/dev/null || touch "$TARGET"
else
echo "do $DO_DEPTH$TARGET exists." >&2
fi

View file

@ -134,10 +134,12 @@ def _build(t):
log('%s\n' % relpath(t, vars.STARTDIR))
rv = subprocess.call(argv, preexec_fn=lambda: _preexec(t),
stdout=f.fileno())
st = os.stat(tmpname)
stampfile = sname('stamp', t)
if rv==0:
if st.st_size:
if os.path.exists(tmpname) and os.stat(tmpname).st_size:
# there's a race condition here, but if the tmpfile disappears
# at *this* point you deserve to get an error, because you're
# doing something totally scary.
os.rename(tmpname, t)
else:
unlink(tmpname)

View file

@ -1,2 +1,3 @@
redo-ifchange hello yellow bellow c d
redo-ifchange hello yellow bellow c d deltest deltest2

2
t/deltest.do Normal file
View file

@ -0,0 +1,2 @@
# remove an empty output file
rm -f $3

3
t/deltest2.do Normal file
View file

@ -0,0 +1,3 @@
# delete a non-empty output file
echo hello
rm -f $3