<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self):
 """ Write the file, forcing the proper permissions """

        with root():
            self._write_log()
            with open(self.path, 'w') as f:
                # file owner
                os.chown(self.path, self.uid(), self.gid())

                # mode
                if self.mode:
                    oldmask = os.umask(0)
                    os.chmod(self.path, self.mode)
                    os.umask(oldmask)

                f.write(self.contents())