[1.7.x] Fixed #22299 -- Cleanup wizard temp files when possible.

Thanks to @erikr for the review.

Backport of fa8b4735287c92b03d23823de8a4e1168d1951d9 from master.