mirror of
https://github.com/python/cpython.git
synced 2025-10-04 22:20:46 +00:00
bpo-30693: zip+tarfile: sort directory listing (#2263)
tarfile and zipfile now sort directory listing to generate tar and zip archives in a more reproducible way. See also https://reproducible-builds.org/docs/stable-inputs/ on that topic.
This commit is contained in:
parent
209108bd69
commit
57750be4ad
7 changed files with 39 additions and 6 deletions
|
|
@ -1940,7 +1940,7 @@ class PyZipFile(ZipFile):
|
|||
if self.debug:
|
||||
print("Adding", arcname)
|
||||
self.write(fname, arcname)
|
||||
dirlist = os.listdir(pathname)
|
||||
dirlist = sorted(os.listdir(pathname))
|
||||
dirlist.remove("__init__.py")
|
||||
# Add all *.py files and package subdirectories
|
||||
for filename in dirlist:
|
||||
|
|
@ -1965,7 +1965,7 @@ class PyZipFile(ZipFile):
|
|||
# This is NOT a package directory, add its files at top level
|
||||
if self.debug:
|
||||
print("Adding files from directory", pathname)
|
||||
for filename in os.listdir(pathname):
|
||||
for filename in sorted(os.listdir(pathname)):
|
||||
path = os.path.join(pathname, filename)
|
||||
root, ext = os.path.splitext(filename)
|
||||
if ext == ".py":
|
||||
|
|
@ -2116,7 +2116,7 @@ def main(args=None):
|
|||
elif os.path.isdir(path):
|
||||
if zippath:
|
||||
zf.write(path, zippath)
|
||||
for nm in os.listdir(path):
|
||||
for nm in sorted(os.listdir(path)):
|
||||
addToZip(zf,
|
||||
os.path.join(path, nm), os.path.join(zippath, nm))
|
||||
# else: ignore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue