Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with scandir #11

Closed
CivBase opened this issue Jan 4, 2018 · 3 comments
Closed

Conflict with scandir #11

CivBase opened this issue Jan 4, 2018 · 3 comments

Comments

@CivBase
Copy link

@CivBase CivBase commented Jan 4, 2018

The scandir library is an alternative to os.walk with drastically improved efficiency. The improvement was officially implemented in Python 3.5, but the scandir library still exists to support older versions. Unfortunately, using it in conjunction with jaraco.windows seems to cause some issues.

For the example below I have updated sitecustomize.py to include the call to fs.patch_os_module as described in the README.

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.mkdir('testdir')
>>> os.symlink('testdir', 'testlink')
>>> os.path.islink('testdir')
False
>>> os.path.islink('testlink')
True
>>> import scandir
>>> os.path.islink('testdir')
False
>>> os.path.islink('testlink')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<python>\lib\site-packages\jaraco\windows\filesystem\__init__.py", line 94, in islink
    return is_reparse_point(path) and is_symlink(path)
  File "<python>\lib\site-packages\jaraco\windows\filesystem\__init__.py", line 120, in is_symlink
    return _is_symlink(next(find_files(path)))
  File "<python>\lib\site-packages\jaraco\windows\filesystem\__init__.py", line 145, in find_files
    handle = api.FindFirstFile(spec, byref(fd))
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_WIN32_FIND_DATAW instance instead of pointer to WIN32_FIND_DATA

It looks like scandir patches ctypes.windll.kernel32.FindFirstFileW, which is also patched by jaraco.windows.api.filesystem.

I haven't looked into the issue enough to figure out a solution, but it sure would be nice to take advantage of both of these libraries.

@jaraco

This comment has been minimized.

Copy link
Owner

@jaraco jaraco commented Jan 4, 2018

Here's where scandir patches FindFistFileW. Here's where jaraco.windows does.

Scandir uses ctypes.wintypes.WIN32_FIND_DATAW, and jaraco.windows uses its own WIN32_FIND_DATA Structure. Probably the fix is for jaraco.windows to use the structure found in wintypes.

@jaraco jaraco closed this in a1f40cb Jan 5, 2018
@jaraco

This comment has been minimized.

Copy link
Owner

@jaraco jaraco commented Jan 5, 2018

Thanks for the bug report. 3.8.1 is going out now with what I believe is a proper fix.

@CivBase

This comment has been minimized.

Copy link
Author

@CivBase CivBase commented Jan 5, 2018

That fixed it on my end. Thanks for such a quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.