Set permissions on external files (fixes #1045, fixes #1047)