Improve file handling and permissions.

File visibility can now be changed, and they can be
removed. Permissions are checked in a more sane way.