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
d54377d2
Commit
d54377d2
authored
Jan 06, 2016
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Plain Diff
Issue #24120: Ignore PermissionError in pathlib.Path.[r]glob(). Ulrich Petri. (Merge 3.4->3.5)
parents
f34c3fe2
6c2d33a2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
37 deletions
+59
-37
Lib/pathlib.py
Lib/pathlib.py
+35
-25
Lib/test/test_pathlib.py
Lib/test/test_pathlib.py
+20
-12
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pathlib.py
View file @
d54377d2
...
...
@@ -499,12 +499,15 @@ class _PreciseSelector(_Selector):
_Selector
.
__init__
(
self
,
child_parts
)
def
_select_from
(
self
,
parent_path
,
is_dir
,
exists
,
listdir
):
try
:
if
not
is_dir
(
parent_path
):
return
path
=
parent_path
.
_make_child_relpath
(
self
.
name
)
if
exists
(
path
):
for
p
in
self
.
successor
.
_select_from
(
path
,
is_dir
,
exists
,
listdir
):
yield
p
except
PermissionError
:
return
class
_WildcardSelector
(
_Selector
):
...
...
@@ -514,6 +517,7 @@ class _WildcardSelector(_Selector):
_Selector
.
__init__
(
self
,
child_parts
)
def
_select_from
(
self
,
parent_path
,
is_dir
,
exists
,
listdir
):
try
:
if
not
is_dir
(
parent_path
):
return
cf
=
parent_path
.
_flavour
.
casefold
...
...
@@ -523,6 +527,9 @@ class _WildcardSelector(_Selector):
path
=
parent_path
.
_make_child_relpath
(
name
)
for
p
in
self
.
successor
.
_select_from
(
path
,
is_dir
,
exists
,
listdir
):
yield
p
except
PermissionError
:
return
class
_RecursiveWildcardSelector
(
_Selector
):
...
...
@@ -539,6 +546,7 @@ class _RecursiveWildcardSelector(_Selector):
yield
p
def
_select_from
(
self
,
parent_path
,
is_dir
,
exists
,
listdir
):
try
:
if
not
is_dir
(
parent_path
):
return
with
_cached
(
listdir
)
as
listdir
:
...
...
@@ -552,6 +560,8 @@ class _RecursiveWildcardSelector(_Selector):
yielded
.
add
(
p
)
finally
:
yielded
.
clear
()
except
PermissionError
:
return
#
...
...
Lib/test/test_pathlib.py
View file @
d54377d2
...
...
@@ -1199,26 +1199,33 @@ class _BasePathTest(object):
# (BASE)
# |
# |-- dirA/
# |-- linkC -> "../dirB"
# |-- dirB/
# |-- brokenLink -> non-existing
# |-- dirA
# | `-- linkC -> ../dirB
# |-- dirB
# | |-- fileB
# |-- linkD -> "../dirB"
# |-- dirC/
# | |-- fileC
# | |-- fileD
# | `-- linkD -> ../dirB
# |-- dirC
# | |-- dirD
# | | `-- fileD
# | `-- fileC
# |-- dirE
# |-- fileA
# |-- linkA ->
"fileA"
#
|-- linkB -> "dirB"
# |-- linkA ->
fileA
#
`-- linkB -> dirB
#
def
setUp
(
self
):
def
cleanup
():
os
.
chmod
(
join
(
'dirE'
),
0o777
)
support
.
rmtree
(
BASE
)
self
.
addCleanup
(
cleanup
)
os
.
mkdir
(
BASE
)
self
.
addCleanup
(
support
.
rmtree
,
BASE
)
os
.
mkdir
(
join
(
'dirA'
))
os
.
mkdir
(
join
(
'dirB'
))
os
.
mkdir
(
join
(
'dirC'
))
os
.
mkdir
(
join
(
'dirC'
,
'dirD'
))
os
.
mkdir
(
join
(
'dirE'
))
with
open
(
join
(
'fileA'
),
'wb'
)
as
f
:
f
.
write
(
b"this is file A
\
n
"
)
with
open
(
join
(
'dirB'
,
'fileB'
),
'wb'
)
as
f
:
...
...
@@ -1227,6 +1234,7 @@ class _BasePathTest(object):
f
.
write
(
b"this is file C
\
n
"
)
with
open
(
join
(
'dirC'
,
'dirD'
,
'fileD'
),
'wb'
)
as
f
:
f
.
write
(
b"this is file D
\
n
"
)
os
.
chmod
(
join
(
'dirE'
),
0
)
if
not
symlink_skip_reason
:
# Relative symlinks
os
.
symlink
(
'fileA'
,
join
(
'linkA'
))
...
...
@@ -1363,7 +1371,7 @@ class _BasePathTest(object):
p
=
P
(
BASE
)
it
=
p
.
iterdir
()
paths
=
set
(
it
)
expected
=
[
'dirA'
,
'dirB'
,
'dirC'
,
'fileA'
]
expected
=
[
'dirA'
,
'dirB'
,
'dirC'
,
'
dirE'
,
'
fileA'
]
if
not
symlink_skip_reason
:
expected
+=
[
'linkA'
,
'linkB'
,
'brokenLink'
]
self
.
assertEqual
(
paths
,
{
P
(
BASE
,
q
)
for
q
in
expected
})
...
...
Misc/ACKS
View file @
d54377d2
...
...
@@ -1106,6 +1106,7 @@ Gabriel de Perthuis
Tim Peters
Benjamin Peterson
Joe Peterson
Ulrich Petri
Chris Petrilli
Roumen Petrov
Bjorn Pettersen
...
...
Misc/NEWS
View file @
d54377d2
...
...
@@ -41,6 +41,9 @@ Core and Builtins
Library
-------
- Issue #24120: Ignore PermissionError when traversing a tree with
pathlib.Path.[r]glob(). Patch by Ulrich Petri.
- Issue #25447: fileinput now uses sys.stdin as-is if it does not have a
buffer attribute (restores backward compatibility).
...
...
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