Ensure temporary file is complete before using it.

Change-Id: Iabb010c6f4df23dd734ae68a35055b829722ca04