Handle files without meta data correctly.

Sometimes file.flags is `NoneType`. Index-based access raises an `KeyError`.
Check if key exists before accessing.