Improve robustness when generating dynamic files.

Signed-off-by: Timo Kinnunen <timo.kinnunen@gmail.com>