]> git.pld-linux.org Git - packages/python-scandir.git/commitdiff
- added linux patch (fix python/ctypes implementation on X32 ABI or with long names) auto/th/python-scandir-1.5-2
authorJakub Bogusz <qboosh@pld-linux.org>
Thu, 23 Mar 2017 20:15:11 +0000 (21:15 +0100)
committerJakub Bogusz <qboosh@pld-linux.org>
Thu, 23 Mar 2017 20:15:11 +0000 (21:15 +0100)
- pass PYTHONPATH to test also C implementation
- release 2

python-scandir-linux.patch [new file with mode: 0644]
python-scandir.spec

diff --git a/python-scandir-linux.patch b/python-scandir-linux.patch
new file mode 100644 (file)
index 0000000..54bae9a
--- /dev/null
@@ -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:
index 5c263f1133eda5ce14a334fa900ae2e1135b5bb6..bbd19c95f21f14869be883394cc5ec98054319f4 100644 (file)
@@ -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
This page took 0.072595 seconds and 4 git commands to generate.