def gzopen_without_timestamps(name, mode="r", fileobj=None, compresslevel=9, **kwargs): """ !! Method overrided by laso to pass mtime=0 (!=None) to avoid time.time() was setted in Gzip file causing md5 to change. Not possible using the previous tarfile open because arguments are not passed to GzipFile constructor """ from tarfile import CompressionError, ReadError if mode not in ("r", "w"): raise ValueError("mode must be 'r' or 'w'") try: import gzip gzip.GzipFile except (ImportError, AttributeError): raise CompressionError("gzip module is not available") try: fileobj = gzip.GzipFile(name, mode, compresslevel, fileobj, mtime=0) except OSError: if fileobj is not None and mode == 'r': raise ReadError("not a gzip file") raise try: t = tarfile.TarFile.taropen(name, mode, fileobj, **kwargs) except IOError: fileobj.close() if mode == 'r': raise ReadError("not a gzip file") raise except: fileobj.close() raise t._extfileobj = False return t
def gzopen_without_timestamps(name, mode="r", fileobj=None, compresslevel=None, **kwargs): """ !! Method overrided by laso to pass mtime=0 (!=None) to avoid time.time() was setted in Gzip file causing md5 to change. Not possible using the previous tarfile open because arguments are not passed to GzipFile constructor """ from tarfile import CompressionError, ReadError compresslevel = compresslevel or int( os.getenv("CONAN_COMPRESSION_LEVEL", 9)) if mode not in ("r", "w"): raise ValueError("mode must be 'r' or 'w'") try: import gzip gzip.GzipFile except (ImportError, AttributeError): raise CompressionError("gzip module is not available") try: fileobj = gzip.GzipFile(name, mode, compresslevel, fileobj, mtime=0) except OSError: if fileobj is not None and mode == 'r': raise ReadError("not a gzip file") raise try: # Format is forced because in Python3.8, it changed and it generates different tarfiles # with different checksums, which break hashes of tgzs t = tarfile.TarFile.taropen(name, mode, fileobj, format=tarfile.GNU_FORMAT, **kwargs) except IOError: fileobj.close() if mode == 'r': raise ReadError("not a gzip file") raise except Exception: fileobj.close() raise t._extfileobj = False return t