Properly wrap file manipulation in context

Signed-off-by: Michal Čihař <michal@cihar.com>