From 33ac1271732a876642eb9f2c892363e658631e5c Mon Sep 17 00:00:00 2001 From: Jan Wester Date: Thu, 7 Mar 2019 23:13:37 +0100 Subject: [PATCH] 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. --- manuskript/load_save/version_0.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manuskript/load_save/version_0.py b/manuskript/load_save/version_0.py index 2e31150..e89aa22 100644 --- a/manuskript/load_save/version_0.py +++ b/manuskript/load_save/version_0.py @@ -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