[issue2824] zipfile to handle duplicate files in archive

Martin McNickle report at bugs.python.org
Tue May 13 14:42:30 CEST 2008


Martin McNickle <mmcnickle at gmail.com> added the comment:

The mechanism for throwing an error has been written, however for the
case of a duplicated filename, it appears to have been deliberatly not
been used by the original author.:

 def _writecheck(self, zinfo):
        """Check for errors before writing a file to the archive."""
        if zinfo.filename in self.NameToInfo:
            if self.debug:      # Warning for duplicate names
                print "Duplicate name:", zinfo.filename
        if self.mode not in ("w", "a"):
            raise RuntimeError, 'write() requires mode "w" or "a"'
        ...

Putting a 'replace=True' switch seems a little clumsy, it would be much
better to raise an error, or allow the user a way to globally control
what happens in this case, i.e. overwrite the existing file or drop it.
 Adding a global behaviour switch seems to be the best way to preserve
backwards compatibility.

What do people think is the best way?

-- Martin

----------
nosy: +BitTorment

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2824>
__________________________________


More information about the Python-bugs-list mailing list