Fix logic for extra adds of identical files.

Additionally, add a test.