repository: Fix potential race condition

If we crash between compact_segments() and write_index() and the
transaction deletes objects that are newer than the current index
might become undeleted.