This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author joernheissler
Recipients joernheissler
Date 2019-08-06.06:57:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565074650.65.0.762547380277.issue37772@roundup.psfhosted.org>
In-reply-to
Content
Hello,


#!/usr/bin/python3.8

from zipfile import ZipFile, Path
import io

def recurse_print(parent):
    for child in parent.iterdir():
        if child.is_file():
            print(child, child.read_text())
        if child.is_dir():
            recurse_print(child)

data = io.BytesIO()
zf = ZipFile(data, "w")
zf.writestr("a.txt", "content of a")
zf.writestr("b/c.txt", "content of c")
zf.writestr("b/d/e.txt", "content of e")
zf.writestr("b/f.txt", "content of f")
zf.filename = "abcde.zip"
root = Path(zf)
recurse_print(root)


Expected result:

abcde.zip/a.txt content of a
abcde.zip/b/c.txt content of c
abcde.zip/b/f.txt content of f
abcde.zip/b/d/e.txt content of e

Actual result:

abcde.zip/a.txt content of a
abcde.zip/b/c.txt content of c
abcde.zip/b/f.txt content of f
abcde.zip/b/d/e.txt content of e
abcde.zip/b/c.txt content of c
abcde.zip/b/f.txt content of f
abcde.zip/b/d/e.txt content of e


Path._add_implied_dirs adds the sub directory "b/" twice: once for each direct child (i.e. "c.txt" and "f.txt")


And similarly:

data = io.BytesIO()
zf = ZipFile(data, "w")
zf.writestr("a.txt", "content of a")
zf.writestr("b/d/e.txt", "content of e")
zf.filename = "abcde.zip"
root = Path(zf)
recurse_print(root)

Expected result:

abcde.zip/a.txt content of a
abcde.zip/b/d/e.txt content of e

Actual result:

abcde.zip/a.txt content of a

Here, Path._add_implied_dirs doesn't add "b/" at all, because there are no direct childs of "b".
History
Date User Action Args
2019-08-06 06:57:30joernheisslersetrecipients: + joernheissler
2019-08-06 06:57:30joernheisslersetmessageid: <1565074650.65.0.762547380277.issue37772@roundup.psfhosted.org>
2019-08-06 06:57:30joernheisslerlinkissue37772 messages
2019-08-06 06:57:30joernheisslercreate