Fix bugs deleting temporary files and their containing directory.