summaryrefslogtreecommitdiff
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index bd92dedd67..6bdbf36e83 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1802,11 +1802,13 @@ class TarFile(object):
fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
t = cls.taropen(name, mode, fileobj, **kwargs)
except IOError:
- if not extfileobj:
+ if not extfileobj and fileobj is not None:
fileobj.close()
+ if fileobj is None:
+ raise
raise ReadError("not a gzip file")
except:
- if not extfileobj:
+ if not extfileobj and fileobj is not None:
fileobj.close()
raise
t._extfileobj = extfileobj