Skip to content

ZipReadFS claims to be case-insensitive but probably shouldn't #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcoshea opened this issue Mar 13, 2022 · 4 comments
Closed

ZipReadFS claims to be case-insensitive but probably shouldn't #12

dcoshea opened this issue Mar 13, 2022 · 4 comments
Labels

Comments

@dcoshea
Copy link

dcoshea commented Mar 13, 2022

The fix for issue #6 enables something like my test case in that issue to work - specifying paths within a .zip file works regardless of the case of the path within the .zip file, at least when I provide the path using the same case as appears in the .zip file:

>>> zip.listdir("/testdir")
['lower', 'Mixed', 'UPPER']
>>> zip.open('/testdir/lower').read()
'lower\n'
>>> zip.open('/testdir/Mixed').read()
'mixed\n'
>>> zip.open('/testdir/UPPER').read()
'upper\n'

However, it doesn't work if I specify a path in the wrong case:

>>> zip.open('/testdir/upper').read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/site-packages/fs/base.py", line 1224, in open
    bin_file = self.openbin(path, mode=bin_mode, buffering=buffering)
  File "[...]/site-packages/fs/archive/zipfs/__init__.py", line 217, in openbin
    raise errors.ResourceNotFound(path)
fs.errors.ResourceNotFound: resource '/testdir/upper' not found

despite this claim that the filesystem is not case-sensitive:

>>> zip.getmeta()["case_insensitive"]
True

The Info-ZIP zip manual page suggests that .zip files are in fact case-sensitive:

it is possible the archive came from a system where case does matter and the archive could include both Bar and bar as separate files in the archive.

The Python 3.6.13 zipfile module's documentation doesn't say anything about case, but at least in Python 3.6.8 the module seems to be similarly case-sensitive.

I think then that the bug is just that zip.getmeta()["case_insensitive"] returns True when it should return False.

Incidentally fs.zipfs.ReadZipFS which comes with PyFilesystem has the same bug. I'll try to get around to filing a bug against that package too.

@althonos
Copy link
Owner

Thanks for the report, i forgot to change this but indeed #6 has shown that Zip files were not case insensitive. I'm actually doing some work on Pyfilesystem2 at the moment including a refactoring of the _ZipExtFile to use the seeking mechanism provided by CPython instead of our hack on Python3.7+, so I'll patch this bug as the same time.

@althonos althonos added the bug label Mar 13, 2022
@althonos
Copy link
Owner

This will be partially fixed in PyFilesystem/pyfilesystem2#527.

@dcoshea
Copy link
Author

dcoshea commented Mar 20, 2022

Thanks very much! I actually use PyFilesystem's .zip file handling rather than fs.archive's (due to issue #3), and I found this bug by accident when trying to investigate a problem in PyFilesystem - I imported the wrong module and used the wrong class - so you fixed the bug that actually matters to me.

@althonos
Copy link
Owner

I marked TarReadFS and ZipReadFS as case-sensitive in release v0.7.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants