diff options
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r-- | Lib/tarfile.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 47bd9a730b..54bb1b85b8 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1060,6 +1060,10 @@ class TarFile(object): self.mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode] if not fileobj: + if self._mode == "a" and not os.path.exists(self.name): + # Create nonexistent files in append mode. + self._mode = "w" + self.mode = "wb" fileobj = file(self.name, self.mode) self._extfileobj = False else: @@ -1093,7 +1097,8 @@ class TarFile(object): self.fileobj.seek(0) break if tarinfo is None: - self.fileobj.seek(- BLOCKSIZE, 1) + if self.offset > 0: + self.fileobj.seek(- BLOCKSIZE, 1) break if self._mode in "aw": @@ -1120,7 +1125,7 @@ class TarFile(object): 'r:' open for reading exclusively uncompressed 'r:gz' open for reading with gzip compression 'r:bz2' open for reading with bzip2 compression - 'a' or 'a:' open for appending + 'a' or 'a:' open for appending, creating the file if necessary 'w' or 'w:' open for writing without compression 'w:gz' open for writing with gzip compression 'w:bz2' open for writing with bzip2 compression |