Fix possible race condition with directory creating.