Details
Details
- Reviewers
pulkit indygreg - Group Reviewers
hg-reviewers - Commits
- rHG7f9a6f5f7612: archival: our filenames are bytes, not strs
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
pulkit | |
indygreg |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
fileobj, timestamp=mtime) | fileobj, timestamp=mtime) | ||||
self.fileobj = gzfileobj | self.fileobj = gzfileobj | ||||
return tarfile.TarFile.taropen( | return tarfile.TarFile.taropen( | ||||
name, pycompat.sysstr(mode), gzfileobj) | name, pycompat.sysstr(mode), gzfileobj) | ||||
else: | else: | ||||
return tarfile.open( | return tarfile.open( | ||||
name, pycompat.sysstr(mode + kind), fileobj) | name, pycompat.sysstr(mode + kind), fileobj) | ||||
if isinstance(dest, str): | if isinstance(dest, bytes): | ||||
self.z = taropen('w:', name=dest) | self.z = taropen('w:', name=dest) | ||||
else: | else: | ||||
self.z = taropen('w|', fileobj=dest) | self.z = taropen('w|', fileobj=dest) | ||||
def addfile(self, name, mode, islink, data): | def addfile(self, name, mode, islink, data): | ||||
name = pycompat.fsdecode(name) | name = pycompat.fsdecode(name) | ||||
i = tarfile.TarInfo(name) | i = tarfile.TarInfo(name) | ||||
i.mtime = self.mtime | i.mtime = self.mtime | ||||
def tell(self): | def tell(self): | ||||
return self.offset | return self.offset | ||||
class zipit(object): | class zipit(object): | ||||
'''write archive to zip file or stream. can write uncompressed, | '''write archive to zip file or stream. can write uncompressed, | ||||
or compressed with deflate.''' | or compressed with deflate.''' | ||||
def __init__(self, dest, mtime, compress=True): | def __init__(self, dest, mtime, compress=True): | ||||
if not isinstance(dest, str): | if not isinstance(dest, bytes): | ||||
try: | try: | ||||
dest.tell() | dest.tell() | ||||
except (AttributeError, IOError): | except (AttributeError, IOError): | ||||
dest = tellable(dest) | dest = tellable(dest) | ||||
self.z = zipfile.ZipFile(pycompat.fsdecode(dest), r'w', | self.z = zipfile.ZipFile(pycompat.fsdecode(dest), r'w', | ||||
compress and zipfile.ZIP_DEFLATED or | compress and zipfile.ZIP_DEFLATED or | ||||
zipfile.ZIP_STORED) | zipfile.ZIP_STORED) | ||||