restore write protection on directories

* @dagss originally put code in that didn't protect directories
* @certik introduced a non-portable fix to add directory protection
* I removed the non-portable code when introducing `develop` functionality.
  (see 9d9f0b728bfc88d4b435b691bd95e3171159f1af )

Now I'm re-adding portable directory protection to protect us from
further foot-shooting.