precreate directories only when needed
fix chown when uid or gid are undef