Fix bug when setting file permissions