Added retries on fs.chmod to avoid errors while restoring permissions.

WARNING: this is a temporary fix which uses synchronous methods.
The real synchro mechanism to implement is not yet understood.