Skip to content

Commit

Permalink
[fix] Improve error message when trying to open zipfile with Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmlnkn committed May 27, 2022
1 parent f7c3933 commit bc61e2c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/ratarmountcore/SQLiteIndexedTar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,9 @@ def _detectCompression(fileobj: IO[bytes], printDebug: int = 0) -> Optional[str]

oldOffset = fileobj.tell()
for compressionId, compression in supportedCompressions.items():
if compressionId in ['rar', 'zip']:
continue

# The header check is a necessary condition not a sufficient condition.
# Especially for gzip, which only has 2 magic bytes, false positives might happen.
# Therefore, only use the magic bytes based check if the module could not be found
Expand Down
2 changes: 1 addition & 1 deletion core/ratarmountcore/compressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# The file object returned by ZipFile.open is not seekable in Python 3.6 for some reason.
# Therefore disable ZIP support there!
# I don't see it documented, instead I tested different Python versions with Docker.
if sys.version_info[1] > 6:
if sys.version_info[0] == 3 and sys.version_info[1] > 6:
import zipfile
else:
zipfile = None
Expand Down
2 changes: 1 addition & 1 deletion core/ratarmountcore/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def openMountSource(fileOrPath: Union[str, IO[bytes]], **options) -> MountSource
if hasattr(fileOrPath, 'seek'):
fileOrPath.seek(0) # type: ignore

if 'zipfile' in sys.modules:
if 'zipfile' in sys.modules and zipfile is not None:
try:
# is_zipfile is much too lax when testing for ZIPs because it's only testing for the central directory
# at the end of the file not the magic bits at the beginning. Meaning, if another non-ZIP archive has
Expand Down

0 comments on commit bc61e2c

Please sign in to comment.