/usr/lib/python3/dist-packages/skytools/gzlog.py is in python3-skytools 3.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | """Atomic append of gzipped data.
The point is - if several gzip streams are concatenated,
they are read back as one whole stream.
"""
from __future__ import division, absolute_import, print_function
import gzip
from io import BytesIO
__all__ = ['gzip_append']
#
# gzip storage
#
def gzip_append(filename, data, level=6):
"""Append a block of data to file with safety checks."""
# compress data
buf = BytesIO()
g = gzip.GzipFile(fileobj=buf, compresslevel=level, mode="w")
g.write(data)
g.close()
zdata = buf.getvalue()
# append, safely
f = open(filename, "ab+", 0)
f.seek(0, 2)
pos = f.tell()
try:
f.write(zdata)
f.close()
except Exception as ex:
# rollback on error
f.seek(pos, 0)
f.truncate()
f.close()
raise ex
|