Directory entries in ZIP break loading code

While tackling issue #529, I stumbled across the odd behaviour that
re-compressing the archive with 7-Zip broke what should be a valid
Manuskript project.

After investigation it turned out that the code that loads the texts
sensibly expects there to only be files tracked in the files dictionary.

It is completely valid for a zip file to contain entries describing the
contained directories. The logical fix is to simply avoid adding these
directory entries to our files dictionary in the first place.
This commit is contained in:
Jan Wester 2019-03-07 23:13:37 +01:00 committed by Curtis Gedak
parent dd56797cd7
commit 33ac127173

View file

@ -178,7 +178,10 @@ def loadFilesFromZip(zipname):
zf = zipfile.ZipFile(zipname)
files = {}
for f in zf.namelist():
files[os.path.normpath(f)] = zf.read(f)
# Some archiving programs (e.g. 7-Zip) also store entries for the directories when
# creating an archive. We have no use for these entries; skip them entirely.
if f[-1:] != '/':
files[os.path.normpath(f)] = zf.read(f)
return files