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
38485592
Commit
38485592
authored
Sep 17, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28075: Check for ERROR_ACCESS_DENIED in Windows implementation of os.stat()
Patch by Eryk Sun.
parent
bdde7f36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
Lib/test/test_os.py
Lib/test/test_os.py
+19
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/posixmodule.c
Modules/posixmodule.c
+4
-2
No files found.
Lib/test/test_os.py
View file @
38485592
...
...
@@ -432,6 +432,25 @@ class StatAttributeTests(unittest.TestCase):
result
.
st_file_attributes
&
stat
.
FILE_ATTRIBUTE_DIRECTORY
,
stat
.
FILE_ATTRIBUTE_DIRECTORY
)
@
unittest
.
skipUnless
(
sys
.
platform
==
"win32"
,
"Win32 specific tests"
)
def
test_access_denied
(
self
):
# Default to FindFirstFile WIN32_FIND_DATA when access is
# denied. See issue 28075.
# os.environ['TEMP'] should be located on a volume that
# supports file ACLs.
fname
=
os
.
path
.
join
(
os
.
environ
[
'TEMP'
],
self
.
fname
)
self
.
addCleanup
(
support
.
unlink
,
fname
)
create_file
(
fname
,
b'ABC'
)
# Deny the right to [S]YNCHRONIZE on the file to
# force CreateFile to fail with ERROR_ACCESS_DENIED.
DETACHED_PROCESS
=
8
subprocess
.
check_call
(
[
'icacls.exe'
,
fname
,
'/deny'
,
'Users:(S)'
],
creationflags
=
DETACHED_PROCESS
)
result
=
os
.
stat
(
fname
)
self
.
assertNotEqual
(
result
.
st_size
,
0
)
class
UtimeTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
Misc/NEWS
View file @
38485592
...
...
@@ -71,6 +71,9 @@ Core and Builtins
Library
-------
- Issue #28075: Check for ERROR_ACCESS_DENIED in Windows implementation of
os.stat(). Patch by Eryk Sun.
- Issue #25270: Prevent codecs.escape_encode() from raising SystemError when
an empty bytestring is passed.
...
...
Modules/posixmodule.c
View file @
38485592
...
...
@@ -1515,7 +1515,9 @@ win32_xstat_impl(const char *path, struct _Py_stat_struct *result,
/* Either the target doesn't exist, or we don't have access to
get a handle to it. If the former, we need to return an error.
If the latter, we can use attributes_from_dir. */
if
(
GetLastError
()
!=
ERROR_SHARING_VIOLATION
)
DWORD
lastError
=
GetLastError
();
if
(
lastError
!=
ERROR_ACCESS_DENIED
&&
lastError
!=
ERROR_SHARING_VIOLATION
)
return
-
1
;
/* Could not get attributes on open file. Fall back to
reading the directory. */
...
...
@@ -1525,7 +1527,7 @@ win32_xstat_impl(const char *path, struct _Py_stat_struct *result,
if
(
info
.
dwFileAttributes
&
FILE_ATTRIBUTE_REPARSE_POINT
)
{
if
(
traverse
)
{
/* Should traverse, but could not open reparse point handle */
SetLastError
(
ERROR_SHARING_VIOLATION
);
SetLastError
(
lastError
);
return
-
1
;
}
}
...
...
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