diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-05-15 14:32:21 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-05-15 14:32:21 (GMT) |
commit | 66bfcc1b0f3b1eb4905b3ef1054b8afc1219aacb (patch) | |
tree | dab98c23d5c524b1ceb61bb1a6d89efec416ddbc /Lib/os.py | |
parent | 0fb41b56ea1415943569ee6dda1c9d1aec952c37 (diff) | |
download | cpython-66bfcc1b0f3b1eb4905b3ef1054b8afc1219aacb.zip cpython-66bfcc1b0f3b1eb4905b3ef1054b8afc1219aacb.tar.gz cpython-66bfcc1b0f3b1eb4905b3ef1054b8afc1219aacb.tar.bz2 |
#14773: Fix os.fwalk() failing on dangling symlinks
Diffstat (limited to 'Lib/os.py')
-rw-r--r-- | Lib/os.py | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -353,13 +353,23 @@ if _exists("openat"): names = flistdir(topfd) dirs, nondirs = [], [] for name in names: - # Here, we don't use AT_SYMLINK_NOFOLLOW to be consistent with - # walk() which reports symlinks to directories as directories. We do - # however check for symlinks before recursing into a subdirectory. - if st.S_ISDIR(fstatat(topfd, name).st_mode): - dirs.append(name) - else: - nondirs.append(name) + try: + # Here, we don't use AT_SYMLINK_NOFOLLOW to be consistent with + # walk() which reports symlinks to directories as directories. + # We do however check for symlinks before recursing into + # a subdirectory. + if st.S_ISDIR(fstatat(topfd, name).st_mode): + dirs.append(name) + else: + nondirs.append(name) + except FileNotFoundError: + try: + # Add dangling symlinks, ignore disappeared files + if st.S_ISLNK(fstatat(topfd, name, AT_SYMLINK_NOFOLLOW) + .st_mode): + nondirs.append(name) + except FileNotFoundError: + continue if topdown: yield toppath, dirs, nondirs, topfd |