Fix logic error that could cause the index to have an empty filename.