Code to check directories are writable to prevent database corruption