From fd2f01f28ca9c7938bbc4f425c40c3c9dc2e1c76 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 2 May 2017 17:59:19 +0200 Subject: [PATCH] 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. --- deltatar/tarfile.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) 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 -- 1.7.1