[packages/python-scandir] - added linux patch (fix python/ctypes implementation on X32 ABI or with long names) - pass PYTHONPA

qboosh qboosh at pld-linux.org
Thu Mar 23 21:12:51 CET 2017


commit 2928c4fd26935adf8c9805219d146b22a3b8071c
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date:   Thu Mar 23 21:15:11 2017 +0100

    - added linux patch (fix python/ctypes implementation on X32 ABI or with long names)
    - pass PYTHONPATH to test also C implementation
    - release 2

 python-scandir-linux.patch | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 python-scandir.spec        |  8 +++---
 2 files changed, 67 insertions(+), 3 deletions(-)
---
diff --git a/python-scandir.spec b/python-scandir.spec
index 5c263f1..bbd19c9 100644
--- a/python-scandir.spec
+++ b/python-scandir.spec
@@ -11,12 +11,13 @@ Summary:	A better directory iterator and faster os.walk() for Python 2
 Summary(pl.UTF-8):	Lepszy iterator po katalogach i szybsze os.walk() dla Pythona 2
 Name:		python-%{module}
 Version:	1.5
-Release:	1
+Release:	2
 License:	BSD
 Group:		Libraries/Python
 #Source0Download: https://github.com/benhoyt/scandir/releases
 Source0:	https://github.com/benhoyt/scandir/archive/v%{version}/%{module}-%{version}.tar.gz
 # Source0-md5:	798407545833aa7011c1ee34b580e902
+Patch0:		%{name}-linux.patch
 URL:		https://github.com/benhoyt/scandir
 %if %{with tests} && %(locale -a | grep -q '^C\.UTF-8$'; echo $?)
 BuildRequires:	glibc-localedb-all
@@ -78,6 +79,7 @@ bibliotece standardowej Pythona 3.5+.
 
 %prep
 %setup -q -n %{module}-%{version}
+%patch0 -p1
 
 %build
 %if %{with python2}
@@ -87,9 +89,9 @@ bibliotece standardowej Pythona 3.5+.
 rm -rf test/testdir
 # Tests fail if unicode is not supported
 LC_ALL=C.UTF-8 \
+PYTHONPATH=$(pwd)/$(echo build-2/lib.linux-*) \
 %{__python} test/run_tests.py
 %endif
-
 %endif
 
 %if %{with python3}
@@ -99,9 +101,9 @@ LC_ALL=C.UTF-8 \
 rm -rf test/testdir
 # Tests fail if unicode is not supported
 LC_ALL=C.UTF-8 \
+PYTHONPATH=$(pwd)/$(echo build-3/lib.linux-*) \
 %{__python3} test/run_tests.py
 %endif
-
 %endif
 
 %install
diff --git a/python-scandir-linux.patch b/python-scandir-linux.patch
new file mode 100644
index 0000000..54bae9a
--- /dev/null
+++ b/python-scandir-linux.patch
@@ -0,0 +1,62 @@
+Fix ctypes/readdir issues on Linux:
+* dirent fields have different size when using X32 ABI (dirent=dirent64 in this case)
+* readdir_r is deprecated and fails with long file names
+
+--- scandir-1.5/scandir.py.orig	2017-03-23 16:05:00.658676902 +0100
++++ scandir-1.5/scandir.py	2017-03-23 20:49:34.708524775 +0100
+@@ -403,14 +403,16 @@
+         import ctypes.util
+ 
+         DIR_p = ctypes.c_void_p
++        libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
++        have_readdir64 = hasattr(libc, 'readdir64')
+ 
+         # Rather annoying how the dirent struct is slightly different on each
+         # platform. The only fields we care about are d_name and d_type.
+         class Dirent(ctypes.Structure):
+             if sys.platform.startswith('linux'):
+                 _fields_ = (
+-                    ('d_ino', ctypes.c_ulong),
+-                    ('d_off', ctypes.c_long),
++                    ('d_ino', ctypes.c_uint64 if have_readdir64 else ctypes.c_ulong),
++                    ('d_off', ctypes.c_int64 if have_readdir64 else ctypes.c_long),
+                     ('d_reclen', ctypes.c_ushort),
+                     ('d_type', ctypes.c_byte),
+                     ('d_name', ctypes.c_char * 256),
+@@ -432,14 +434,13 @@
+         Dirent_p = ctypes.POINTER(Dirent)
+         Dirent_pp = ctypes.POINTER(Dirent_p)
+ 
+-        libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
+         opendir = libc.opendir
+         opendir.argtypes = [ctypes.c_char_p]
+         opendir.restype = DIR_p
+ 
+-        readdir_r = libc.readdir_r
+-        readdir_r.argtypes = [DIR_p, Dirent_p, Dirent_pp]
+-        readdir_r.restype = ctypes.c_int
++        readdir = libc.readdir64 if have_readdir64 else libc.readdir
++        readdir.argtypes = [DIR_p]
++        readdir.restype = Dirent_p
+ 
+         closedir = libc.closedir
+         closedir.argtypes = [DIR_p]
+@@ -546,13 +547,14 @@
+             if not dir_p:
+                 raise posix_error(path)
+             try:
+-                result = Dirent_p()
+                 while True:
+-                    entry = Dirent()
+-                    if readdir_r(dir_p, entry, result):
+-                        raise posix_error(path)
++                    ctypes.set_errno(0)
++                    result = readdir(dir_p)
+                     if not result:
++                        if ctypes.get_errno() != 0:
++                            raise posix_error(path)
+                         break
++                    entry = result.contents
+                     name = entry.d_name
+                     if name not in (b'.', b'..'):
+                         if not is_bytes:
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/python-scandir.git/commitdiff/2928c4fd26935adf8c9805219d146b22a3b8071c



More information about the pld-cvs-commit mailing list