Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP2:GA
python3
python3-sorted_tar.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File python3-sorted_tar.patch of Package python3
From c0cda300325bbc751c6cf9cdc351787271402cd2 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" <bmwiedemann@suse.de> Date: Sun, 18 Jun 2017 03:50:25 +0200 Subject: [PATCH] bpo-30693: zip+tarfile: sort directory listing gh#python/cpython!2263 (upstream released in 3.7.0) Patch: python3-sorted_tar.patch --- Doc/library/tarfile.rst | 3 + Doc/library/zipfile.rst | 5 +- Lib/tarfile.py | 2 Lib/test/test_tarfile.py | 24 ++++++++++ Lib/zipfile.py | 6 +- Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ7.rst | 1 Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ8.rst | 1 7 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ7.rst create mode 100644 Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ8.rst Index: Python-3.6.15/Doc/library/tarfile.rst =================================================================== --- Python-3.6.15.orig/Doc/library/tarfile.rst +++ Python-3.6.15/Doc/library/tarfile.rst @@ -467,6 +467,9 @@ be finalized; only the internally used f The *exclude* parameter is deprecated, please use the *filter* parameter instead. + .. versionchanged:: 3.6.4 + Recursion adds entries in sorted order. + .. method:: TarFile.addfile(tarinfo, fileobj=None) Index: Python-3.6.15/Doc/library/zipfile.rst =================================================================== --- Python-3.6.15.orig/Doc/library/zipfile.rst +++ Python-3.6.15/Doc/library/zipfile.rst @@ -466,7 +466,7 @@ The :class:`PyZipFile` constructor takes :file:`\*.pyc` are added at the top level. If the directory is a package directory, then all :file:`\*.pyc` are added under the package name as a file path, and if any subdirectories are package directories, - all of these are added recursively. + all of these are added recursively in sorted order. *basename* is intended for internal use only. @@ -499,6 +499,9 @@ The :class:`PyZipFile` constructor takes .. versionchanged:: 3.6.2 The *pathname* parameter accepts a :term:`path-like object`. + .. versionchanged:: 3.6.4 + Recursion sorts directory entries. + .. _zipinfo-objects: Index: Python-3.6.15/Lib/tarfile.py =================================================================== --- Python-3.6.15.orig/Lib/tarfile.py +++ Python-3.6.15/Lib/tarfile.py @@ -1955,7 +1955,7 @@ class TarFile(object): elif tarinfo.isdir(): self.addfile(tarinfo) if recursive: - for f in os.listdir(name): + for f in sorted(os.listdir(name)): self.add(os.path.join(name, f), os.path.join(arcname, f), recursive, exclude, filter=filter) Index: Python-3.6.15/Lib/test/test_tarfile.py =================================================================== --- Python-3.6.15.orig/Lib/test/test_tarfile.py +++ Python-3.6.15/Lib/test/test_tarfile.py @@ -1136,6 +1136,30 @@ class WriteTest(WriteTestBase, unittest. finally: support.rmdir(path) + # mock the following: + # os.listdir: so we know that files are in the wrong order + @unittest.mock.patch('os.listdir') + def test_ordered_recursion(self, mock_listdir): + path = os.path.join(TEMPDIR, "directory") + os.mkdir(path) + open(os.path.join(path, "1"), "a").close() + open(os.path.join(path, "2"), "a").close() + mock_listdir.return_value = ["2", "1"] + try: + tar = tarfile.open(tmpname, self.mode) + try: + tar.add(path) + paths = [] + for m in tar.getmembers(): + paths.append(os.path.split(m.name)[-1]) + self.assertEqual(paths, ["directory", "1", "2"]); + finally: + tar.close() + finally: + support.unlink(os.path.join(path, "1")) + support.unlink(os.path.join(path, "2")) + support.rmdir(path) + def test_gettarinfo_pathlike_name(self): with tarfile.open(tmpname, self.mode) as tar: path = pathlib.Path(TEMPDIR) / "file" Index: Python-3.6.15/Lib/zipfile.py =================================================================== --- Python-3.6.15.orig/Lib/zipfile.py +++ Python-3.6.15/Lib/zipfile.py @@ -1860,7 +1860,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: @@ -1885,7 +1885,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": @@ -2042,7 +2042,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 Index: Python-3.6.15/Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ7.rst =================================================================== --- /dev/null +++ Python-3.6.15/Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ7.rst @@ -0,0 +1 @@ +The ZipFile class now recurses directories in a reproducible way. Index: Python-3.6.15/Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ8.rst =================================================================== --- /dev/null +++ Python-3.6.15/Misc/NEWS.d/next/Library/2017-11-27-15-09-49.bpo-30693.yC4mJ8.rst @@ -0,0 +1 @@ +The TarFile class now recurses directories in a reproducible way.
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor