Avoid race condition on file indices.