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
85783166
Commit
85783166
authored
Aug 23, 2016
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 2466: ismount now recognizes mount points user can't access.
Patch by Robin Roth, backport by Xiang Zhang.
parent
89446b2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
2 deletions
+70
-2
Lib/posixpath.py
Lib/posixpath.py
+1
-1
Lib/test/test_posixpath.py
Lib/test/test_posixpath.py
+65
-1
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/posixpath.py
View file @
85783166
...
...
@@ -186,7 +186,7 @@ def ismount(path):
return
False
try
:
s1
=
os
.
lstat
(
path
)
s2
=
os
.
lstat
(
join
(
path
,
'..'
))
s2
=
os
.
lstat
(
realpath
(
join
(
path
,
'..'
)
))
except
os
.
error
:
return
False
# It doesn't exist -- so not a mount point :-)
dev1
=
s1
.
st_dev
...
...
Lib/test/test_posixpath.py
View file @
85783166
import
unittest
from
test
import
symlink_support
from
test
import
test_support
,
test_genericpath
from
test
import
test_support
as
support
...
...
@@ -7,6 +8,11 @@ import os
import
sys
from
posixpath
import
realpath
,
abspath
,
dirname
,
basename
try
:
import
posix
except
ImportError
:
posix
=
None
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
# being an absolute path, so we need this.
...
...
@@ -100,7 +106,7 @@ class PosixPathTest(unittest.TestCase):
f
.
write
(
"foo"
)
f
.
close
()
self
.
assertIs
(
posixpath
.
islink
(
test_support
.
TESTFN
+
"1"
),
False
)
if
hasattr
(
os
,
"symlink"
):
if
symlink_support
.
can_symlink
(
):
os
.
symlink
(
test_support
.
TESTFN
+
"1"
,
test_support
.
TESTFN
+
"2"
)
self
.
assertIs
(
posixpath
.
islink
(
test_support
.
TESTFN
+
"2"
),
True
)
os
.
remove
(
test_support
.
TESTFN
+
"1"
)
...
...
@@ -196,6 +202,64 @@ class PosixPathTest(unittest.TestCase):
def
test_ismount
(
self
):
self
.
assertIs
(
posixpath
.
ismount
(
"/"
),
True
)
def
test_ismount_non_existent
(
self
):
# Non-existent mountpoint.
self
.
assertIs
(
posixpath
.
ismount
(
ABSTFN
),
False
)
try
:
os
.
mkdir
(
ABSTFN
)
self
.
assertIs
(
posixpath
.
ismount
(
ABSTFN
),
False
)
finally
:
safe_rmdir
(
ABSTFN
)
@
symlink_support
.
skip_unless_symlink
def
test_ismount_symlinks
(
self
):
# Symlinks are never mountpoints.
try
:
os
.
symlink
(
"/"
,
ABSTFN
)
self
.
assertIs
(
posixpath
.
ismount
(
ABSTFN
),
False
)
finally
:
os
.
unlink
(
ABSTFN
)
@
unittest
.
skipIf
(
posix
is
None
,
"Test requires posix module"
)
def
test_ismount_different_device
(
self
):
# Simulate the path being on a different device from its parent by
# mocking out st_dev.
save_lstat
=
os
.
lstat
def
fake_lstat
(
path
):
st_ino
=
0
st_dev
=
0
if
path
==
ABSTFN
:
st_dev
=
1
st_ino
=
1
return
posix
.
stat_result
((
0
,
st_ino
,
st_dev
,
0
,
0
,
0
,
0
,
0
,
0
,
0
))
try
:
os
.
lstat
=
fake_lstat
self
.
assertIs
(
posixpath
.
ismount
(
ABSTFN
),
True
)
finally
:
os
.
lstat
=
save_lstat
@
unittest
.
skipIf
(
posix
is
None
,
"Test requires posix module"
)
def
test_ismount_directory_not_readable
(
self
):
# issue #2466: Simulate ismount run on a directory that is not
# readable, which used to return False.
save_lstat
=
os
.
lstat
def
fake_lstat
(
path
):
st_ino
=
0
st_dev
=
0
if
path
.
startswith
(
ABSTFN
)
and
path
!=
ABSTFN
:
# ismount tries to read something inside the ABSTFN directory;
# simulate this being forbidden (no read permission).
raise
OSError
(
"Fake [Errno 13] Permission denied"
)
if
path
==
ABSTFN
:
st_dev
=
1
st_ino
=
1
return
posix
.
stat_result
((
0
,
st_ino
,
st_dev
,
0
,
0
,
0
,
0
,
0
,
0
,
0
))
try
:
os
.
lstat
=
fake_lstat
self
.
assertIs
(
posixpath
.
ismount
(
ABSTFN
),
True
)
finally
:
os
.
lstat
=
save_lstat
def
test_expanduser
(
self
):
self
.
assertEqual
(
posixpath
.
expanduser
(
"foo"
),
"foo"
)
with
test_support
.
EnvironmentVarGuard
()
as
env
:
...
...
Misc/ACKS
View file @
85783166
...
...
@@ -1186,6 +1186,7 @@ Guido van Rossum
Just van Rossum
Hugo van Rossum
Saskia van Rossum
Robin Roth
Clement Rouault
Donald Wallace Rouse II
Liam Routt
...
...
Misc/NEWS
View file @
85783166
...
...
@@ -33,6 +33,9 @@ Core and Builtins
Library
-------
-
Issue
#
2466
:
posixpath
.
ismount
now
correctly
recognizes
mount
points
which
the
user
does
not
have
permission
to
access
.
-
Issue
#
27783
:
Fix
possible
usage
of
uninitialized
memory
in
operator
.
methodcaller
.
-
Issue
#
27774
:
Fix
possible
Py_DECREF
on
unowned
object
in
_sre
.
...
...
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