'Overwrite an existing file if ``overwrite`` is ``True``, otherwise
raise an IOError.  The exact behavior of this method depends on the
_File object state and is only meant for use within the ``_open_*``
internal methods.'

def _overwrite_existing(self, overwrite, fileobj, closed):

    if ((self.file_like and hasattr(fileobj, 'len') and (fileobj.len > 0)) or (os.path.exists(self.name) and (os.path.getsize(self.name) != 0))):
        if overwrite:
            if (self.file_like and hasattr(fileobj, 'truncate')):
                fileobj.truncate(0)
            else:
                if (not closed):
                    fileobj.close()
                os.remove(self.name)
        else:
            raise IOError('File    {!r}    already    exists.'.format(self.name))
