diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2007-02-06 18:38:13 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2007-02-06 18:38:13 (GMT) |
commit | 3f8aca1164099c3f81522a06504e4003df9f6b6d (patch) | |
tree | 8da7db204d2ffcbef3f04e11fa2c3feeb64bd780 /Lib/tarfile.py | |
parent | 5f9c6ae545e006a748f6fd7594852e72376e0c97 (diff) | |
download | cpython-3f8aca1164099c3f81522a06504e4003df9f6b6d.zip cpython-3f8aca1164099c3f81522a06504e4003df9f6b6d.tar.gz cpython-3f8aca1164099c3f81522a06504e4003df9f6b6d.tar.bz2 |
Patch #1652681: create nonexistent files in append mode and
allow appending to empty files.
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 47bd9a7..54bb1b8 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 |