From: Philipp Gesang Date: Tue, 2 May 2017 15:59:19 +0000 (+0200) Subject: properly handle encryption and compression of empty archives X-Git-Tag: v2.2~7^2~135 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=fd2f01f28ca9c7938bbc4f425c40c3c9dc2e1c76;p=python-delta-tar properly handle encryption and compression of empty archives The old implementation always initialized in the ctor regardless of whether contents would be written to the archive. For empty archives this now has to be done in ``.close()`` if no data has been added yet. --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 6e7517d..3d91e43 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -2221,12 +2221,16 @@ class TarFile(object): def close(self): """Close the TarFile. In write-mode, two finishing zero blocks are - appended to the archive. + appended to the archive. A special case are empty archives which are + initialized accordingly so the two mandatory blocks of zeros are + written abiding by the requested encryption and compression settings. """ if self.closed: return if self.mode in "aw": + if self.arcmode & ARCMODE_CONCAT and self.fileobj.tell () == 0: + self.fileobj.next ("") self.fileobj.write(NUL * (BLOCKSIZE * 2)) self.offset += (BLOCKSIZE * 2) # fill up the end with zero-blocks