Message150870
Here's a possible walkfd() implementation.
Example:
"""
$ cat /home/cf/testwalkfd.py
import os
import sys
topfd = os.open(sys.argv[1], os.O_RDONLY)
for rootfd, dirs, files in os.walkfd(topfd):
print(rootfd, dirs, files)
$ ./python ~/testwalkfd.py /etc/apt/
3 ['sources.list.d', 'preferences.d', 'trusted.gpg.d', 'apt.conf.d']
['trustdb.gpg', 'trusted.gpg~', 'sources.list', 'trusted.gpg']
4 [] []
4 [] []
4 [] []
4 [] ['70debconf', '01autoremove', '00trustcdrom']
[44194 refs]
"""
AFAICT, a safe rmtree could be implemented simply with
walkfd(topdown=False), but Antoine's remarks make me thing I missed
something.
> Be aware that you have to manage dirfd's lifetime, which can make things
> interesting.
Basically, this means that doing:
for rootfd, dirs, files in walkfd(topfd):
print(fstat(rootfd), dirs, files))
is valid whereas
print([(fstat(rootfd), dirs, files) for (rootfd, dirs, files) in
walkfd(topfd)]) isn't.
> Also be aware that symlinks mean sometimes you won't have a dirfd: if
> you have a symlink that points to another directory, you can't open that
> directory using openat from the symlink's directory. So if you follow
> symlinks (or have an option to do so) you must also take that case into
> account.
I'm not sure I understand this. Why "you can't open that directory
using openat from the symlink's directory". Could you elaborate? |
File name |
Uploaded |
walkfd.diff
|
neologix,
2012-01-08.15:25:47
|
|
Date |
User |
Action |
Args |
2012-01-08 15:25:49 | neologix | set | recipients:
+ neologix, ncoghlan, pitrou, tarek, rosslagerwall, hynek |
2012-01-08 15:25:48 | neologix | link | issue13734 messages |
2012-01-08 15:25:48 | neologix | create | |
|