[Python-checkins] cpython (merge 3.6 -> default): Issue #28075: Merge from 3.6

berker.peksag python-checkins at python.org
Sat Sep 17 08:50:42 EDT 2016


https://hg.python.org/cpython/rev/b04d5864e59a
changeset:   103880:b04d5864e59a
parent:      103877:c49084a28969
parent:      103879:4071a7cf6437
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Sat Sep 17 15:51:43 2016 +0300
summary:
  Issue #28075: Merge from 3.6

files:
  Lib/test/test_os.py   |  19 +++++++++++++++++++
  Misc/NEWS             |   3 +++
  Modules/posixmodule.c |   6 ++++--
  3 files changed, 26 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -460,6 +460,25 @@
             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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@
 Library
 -------
 
+- Issue #28075: Check for ERROR_ACCESS_DENIED in Windows implementation of
+  os.stat().  Patch by Eryk Sun.
+
 - Issue #22493: Warning message emitted by using inline flags in the middle of
   regular expression now contains a (truncated) regex pattern.
   Patch by Tim Graham.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1545,7 +1545,9 @@
         /* 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. */
@@ -1555,7 +1557,7 @@
         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;
             }
         }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list