mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
delete the custom GzipFileWithTime class
Summary: Remove the custom `GzipFileWithTime` class from `mercurial/archival.py` This code was added in 2007. Presumably back then Python's standard `gzip.GzipFile` class did not support the `mtime` argument. However, this argument is present in Python 2.7+, and we don't care about older versions. The custom `GzipFileWithTime` class breaks in Python 3.8 since Python 3.8 added an extra `compresslevel` argument to the internal `_write_gzip_header()` method. Reviewed By: pixelb Differential Revision: D20484845 fbshipit-source-id: 4e381799d8537c97cd1993273c8efd02743531df
This commit is contained in:
parent
ceca615943
commit
9428d1cf40
@ -121,33 +121,6 @@ class tarit(object):
|
||||
"""write archive to tar file or stream. can write uncompressed,
|
||||
or compress with gzip or bzip2."""
|
||||
|
||||
class GzipFileWithTime(gzip.GzipFile):
|
||||
def __init__(self, *args, **kw):
|
||||
timestamp = None
|
||||
if "timestamp" in kw:
|
||||
timestamp = kw.pop(r"timestamp")
|
||||
if timestamp is None:
|
||||
self.timestamp = time.time()
|
||||
else:
|
||||
self.timestamp = timestamp
|
||||
gzip.GzipFile.__init__(self, *args, **kw)
|
||||
|
||||
def _write_gzip_header(self):
|
||||
self.fileobj.write(b"\037\213") # magic header
|
||||
self.fileobj.write(b"\010") # compression method
|
||||
fname = self.name
|
||||
if fname and fname.endswith(".gz"):
|
||||
fname = fname[:-3]
|
||||
flags = 0
|
||||
if fname:
|
||||
flags = gzip.FNAME
|
||||
self.fileobj.write(pycompat.encodeutf8(chr(flags)))
|
||||
gzip.write32u(self.fileobj, int(self.timestamp)) # noqa
|
||||
self.fileobj.write(b"\002")
|
||||
self.fileobj.write(b"\377")
|
||||
if fname:
|
||||
self.fileobj.write(pycompat.encodeutf8(fname) + b"\000")
|
||||
|
||||
def __init__(self, dest, mtime, kind=""):
|
||||
self.mtime = mtime
|
||||
self.fileobj = None
|
||||
@ -157,8 +130,8 @@ class tarit(object):
|
||||
mode = mode[0]
|
||||
if not fileobj:
|
||||
fileobj = open(name, mode + "b")
|
||||
gzfileobj = self.GzipFileWithTime(
|
||||
name, mode + "b", zlib.Z_BEST_COMPRESSION, fileobj, timestamp=mtime
|
||||
gzfileobj = gzip.GzipFile(
|
||||
name, mode + "b", zlib.Z_BEST_COMPRESSION, fileobj, mtime=mtime
|
||||
)
|
||||
self.fileobj = gzfileobj
|
||||
return tarfile.TarFile.taropen(name, mode, gzfileobj)
|
||||
|
Loading…
Reference in New Issue
Block a user