Respect file permissions, if readonly

First attempt at checking readonly file permissions. Haven't tested thoroughly, but initially seems to work.

Fixes issue #145