From ecaf8618b0890dfda63bd20c48d782eb5b9bcdb2 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Thu, 12 Nov 2020 10:32:06 +0100 Subject: [PATCH] Fix encryption end writing for external fileobjs. The fix in commit 867f75f78 for fixing offset calculations did not take into account that file objects could be given from external code. Correct that case. --- deltatar/tarfile.py | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index d548f92..4a3dba3 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -745,9 +745,17 @@ class _Stream: given, the stream will seek to that position first and back afterwards, and the total of bytes written is not updated. ''' - self.fileobj.write(s, pos) if pos is None: + self.fileobj.write(s) self.bytes_written += len(s) + elif isinstance(self.fileobj, _LowLevelFile): + self.fileobj.write(s, pos) # change offset update in _LowLevelFile + else: # implement the seek here, e.g. for extfileobj + p0 = self.fileobj.tell() + os.lseek (self.fd, pos, os.SEEK_SET) + self.fileobj.write(s) + os.lseek (self.fd, p0, os.SEEK_SET) + # do not update bytes_written def __enc_write(self, s): -- 1.7.1