avoid race condition when creating directories