Close the file earlier, and only move it if it hasn't been
unlinked already