Backport a change from 1.5.22 to 1.5.18 that fixes some issues with
temp dir creation when using relink-based finalization.