Don't overwrite file targets if there is an error during build

This is the same behaviour as make: if, when building a file target,
the function throws an error, then restore the original file.  This
is only an issue if the file has been modified during the function.
That is the case for download.file and pdf though.