cpython: 33a1a3dd0051 (original) (raw)
--- a/Lib/os.py +++ b/Lib/os.py @@ -481,13 +481,13 @@ if {open, stat} <= supports_dir_fd and { dirs.append(name) else: nondirs.append(name)
except FileNotFoundError:[](#l1.7)
except OSError:[](#l1.8) try:[](#l1.9) # Add dangling symlinks, ignore disappeared files[](#l1.10) if st.S_ISLNK(stat(name, dir_fd=topfd, follow_symlinks=False)[](#l1.11) .st_mode):[](#l1.12) nondirs.append(name)[](#l1.13)
except FileNotFoundError:[](#l1.14)
except OSError:[](#l1.15) continue[](#l1.16)
--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -853,38 +853,54 @@ class WalkTests(unittest.TestCase): # SUB11/ no kids # SUB2/ a file kid and a dirsymlink kid # tmp3
# SUB21/ not readable[](#l2.7)
# tmp5[](#l2.8) # link/ a symlink to TESTFN.2[](#l2.9) # broken_link[](#l2.10)
# broken_link2[](#l2.11)
# broken_link3[](#l2.12) # TEST2/[](#l2.13) # tmp4 a lone file[](#l2.14) self.walk_path = join(support.TESTFN, "TEST1")[](#l2.15) self.sub1_path = join(self.walk_path, "SUB1")[](#l2.16) self.sub11_path = join(self.sub1_path, "SUB11")[](#l2.17) sub2_path = join(self.walk_path, "SUB2")[](#l2.18)
sub21_path = join(sub2_path, "SUB21")[](#l2.19) tmp1_path = join(self.walk_path, "tmp1")[](#l2.20) tmp2_path = join(self.sub1_path, "tmp2")[](#l2.21) tmp3_path = join(sub2_path, "tmp3")[](#l2.22)
tmp5_path = join(sub21_path, "tmp3")[](#l2.23) self.link_path = join(sub2_path, "link")[](#l2.24) t2_path = join(support.TESTFN, "TEST2")[](#l2.25) tmp4_path = join(support.TESTFN, "TEST2", "tmp4")[](#l2.26) broken_link_path = join(sub2_path, "broken_link")[](#l2.27)
broken_link2_path = join(sub2_path, "broken_link2")[](#l2.28)
broken_link3_path = join(sub2_path, "broken_link3")[](#l2.29)
# Create stuff. os.makedirs(self.sub11_path) os.makedirs(sub2_path)
os.makedirs(sub21_path)[](#l2.34) os.makedirs(t2_path)[](#l2.35)
for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:[](#l2.37)
for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path, tmp5_path:[](#l2.38) with open(path, "x") as f:[](#l2.39) f.write("I'm " + path + " and proud of it. Blame test_os.\n")[](#l2.40)
if support.can_symlink(): os.symlink(os.path.abspath(t2_path), self.link_path) os.symlink('broken', broken_link_path, True)
self.sub2_tree = (sub2_path, ["link"], ["broken_link", "tmp3"])[](#l2.45)
os.symlink(join('tmp3', 'broken'), broken_link2_path, True)[](#l2.46)
os.symlink(join('SUB21', 'tmp5'), broken_link3_path, True)[](#l2.47)
self.sub2_tree = (sub2_path, ["link", "SUB21"],[](#l2.48)
["broken_link", "broken_link2", "broken_link3",[](#l2.49)
"tmp3"])[](#l2.50) else:[](#l2.51) self.sub2_tree = (sub2_path, [], ["tmp3"])[](#l2.52)
os.chmod(sub21_path, 0)[](#l2.54)
self.addCleanup(os.chmod, sub21_path, stat.S_IRWXU)[](#l2.55)
+ def test_walk_topdown(self): # Walk top-down. all = list(self.walk(self.walk_path))
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,8 @@ Core and Builtins