It was this comment that ticked my semantic alarm:
"check readonly by trying to open the file for writing"