enhance existing code to provide temp file handling

https://issues.sonatype.org/browse/NXCM-5302 - Protect against staging.xml corruption