Fix for non-writable directories

This is the upstream patch for bug #8954, suitably modified to deal with flymake-run-in-place. It should fix issue #12.