bce82efe1f
This avoids issues with overwriting files that are being used.
(cherry picked from d71a5647a3 commit)