index: check for valid filemodes on add

I noticed that we don't check for this, which can lead to invalid filemodes being written out to disk.