[issue39099] scandir.dirfd() method

2019-12-19 Thread Eryk Sun


Eryk Sun  added the comment:

> I am not sure if it's possible to also support Windows.

For reference, FindFirstFileW doesn't support handle-relative names, and 
neither does CreateFileW. At a lower level in Windows NT, NtCreateFile has 
always supported handle-relative names, but CPython doesn't use the NT API.

fd support (not dirfd) could be added to listdir and scandir in Windows. A 
directory can be listed via GetFileInformationByHandleEx: 
FileFullDirectoryInfo. This doesn't query the short name, so it may perform 
better than FindFirstFileW. However, opening a directory with os.open can't be 
supported. VC++ still hasn't documented the _O_OBTAIN_DIR (0x2000) flag.

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


Giampaolo Rodola'  added the comment:

Good point, I didn't consider that. I suppose you're right. =)
Closing.

--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Benjamin Peterson


Benjamin Peterson  added the comment:

Why not just os.open the directory yourself and pass it to os.scandir?

--
nosy: +benjamin.peterson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


Change by Giampaolo Rodola' :


--
keywords: +patch
pull_requests: +17131
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17664

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


New submission from Giampaolo Rodola' :

PR in attachment adds a new dirfd() method to the scandir() object (POSIX 
only). This can be be passed to os.* functions supporting the "dir_fd" 
parameter, and avoid opening a new fd as in:

>>> dirfd = os.open("basename", os.O_RDONLY, dir_fd=topfd)

At the moment I am not sure if it's possible to also support Windows.

--
components: Library (Lib)
messages: 358686
nosy: giampaolo.rodola
priority: normal
severity: normal
status: open
title: scandir.dirfd() method
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com