Won't this create an infinite loop in production mode, or any time logging errors is enabled?

* Log message.
* chmod() fails.
* Error is triggered.
* Log message.
* chmod() fails.
* Loop entered.