Only create temporary directory if needed

This significantly speeds up builds of pre-existing repos.