From: Christian Herdtweck Date: Thu, 12 Nov 2020 09:32:06 +0000 (+0100) Subject: Fix encryption end writing for external fileobjs. X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=ecaf8618b0890dfda63bd20c48d782eb5b9bcdb2;p=python-delta-tar 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. --- 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):