Make the rebuild of the index use a lockfile.

This prevents corruption of the index when multiple builds happen in
parallel and then try to update the index at the same time.
Merge pull request #1 from andrewguy9/use_lockfile

Make the rebuild of the index use a lockfile.