Apply upstream fix for bug #8954, to cope with non-writable directories, suitably modified.
Merge pull request #13 from rrthomas/master

Fix for non-writable directories