Fixes #3542: don't run chmod unless the directory exists