Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
612ef862
Commit
612ef862
authored
May 15, 2012
by
Hynek Schlawack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#14773: Fix os.fwalk() failing on dangling symlinks
parent
45b99206
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
8 deletions
+24
-8
Lib/os.py
Lib/os.py
+17
-7
Lib/test/test_os.py
Lib/test/test_os.py
+5
-1
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/os.py
View file @
612ef862
...
...
@@ -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
...
...
Lib/test/test_os.py
View file @
612ef862
...
...
@@ -651,6 +651,7 @@ class WalkTests(unittest.TestCase):
# SUB2/ a file kid and a dirsymlink kid
# tmp3
# link/ a symlink to TESTFN.2
# broken_link
# TEST2/
# tmp4 a lone file
walk_path
=
join
(
support
.
TESTFN
,
"TEST1"
)
...
...
@@ -663,6 +664,8 @@ class WalkTests(unittest.TestCase):
link_path
=
join
(
sub2_path
,
"link"
)
t2_path
=
join
(
support
.
TESTFN
,
"TEST2"
)
tmp4_path
=
join
(
support
.
TESTFN
,
"TEST2"
,
"tmp4"
)
link_path
=
join
(
sub2_path
,
"link"
)
broken_link_path
=
join
(
sub2_path
,
"broken_link"
)
# Create stuff.
os
.
makedirs
(
sub11_path
)
...
...
@@ -679,7 +682,8 @@ class WalkTests(unittest.TestCase):
else
:
symlink_to_dir
=
os
.
symlink
symlink_to_dir
(
os
.
path
.
abspath
(
t2_path
),
link_path
)
sub2_tree
=
(
sub2_path
,
[
"link"
],
[
"tmp3"
])
symlink_to_dir
(
'broken'
,
broken_link_path
)
sub2_tree
=
(
sub2_path
,
[
"link"
],
[
"broken_link"
,
"tmp3"
])
else
:
sub2_tree
=
(
sub2_path
,
[],
[
"tmp3"
])
...
...
Misc/NEWS
View file @
612ef862
...
...
@@ -31,6 +31,8 @@ Core and Builtins
Library
-------
- Issue 14773: Fix os.fwalk() failing on dangling symlinks.
- Issue 14807: move undocumented tarfile.filemode() to stat.filemode() and add
doc entry. Add tarfile.filemode alias with deprecation warning.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment