mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fixes three tests failing on Windows:
```
Swift(windows-x86_64) :: ModuleInterface/ModuleCache/force-module-loading-mode-archs.swift
Swift(windows-x86_64) :: ModuleInterface/ModuleCache/force-module-loading-mode-framework.swift
Swift(windows-x86_64) :: ModuleInterface/ModuleCache/force-module-loading-mode.swift
```
These test cases remove read access to the `.swiftmodule` . The expected
behavior is that the compiler checks `fs.exists("path-to.swiftmodule")`
, determines that the file exists and chooses to use it instead of the
`.swiftinterface`. Compilation then fails because the file cannot be
read.
e22cf2e993/lib/Frontend/ModuleInterfaceLoader.cpp (L752)
On Windows, we were denying `R` access, which is broader than only read
access to file contents but also includes file attributes and
permissions. This caused `fs.exists` to fail since it relies on
`fs.status`, which could not open the file with `CreateFileW`. The fix
is is to only deny `RD - read data/list directory` access.
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
|
|
import platform
|
|
import subprocess
|
|
import sys
|
|
|
|
if platform.system() == 'Windows':
|
|
import ctypes
|
|
AdvAPI32 = ctypes.windll.Advapi32
|
|
|
|
from ctypes import POINTER
|
|
|
|
UNLEN = 256
|
|
|
|
GetUserNameW = AdvAPI32.GetUserNameW
|
|
GetUserNameW.argtypes = (
|
|
ctypes.c_wchar_p, # _In_Out_ lpBuffer
|
|
POINTER(ctypes.c_uint) # _In_out_ pcBuffer
|
|
)
|
|
GetUserNameW.restype = ctypes.c_uint
|
|
|
|
buffer = ctypes.create_unicode_buffer(UNLEN + 1)
|
|
size = ctypes.c_uint(len(buffer))
|
|
GetUserNameW(buffer, ctypes.byref(size))
|
|
# For NetworkService, Host$ is returned, so we choose have to turn it back
|
|
# into something that icacls understands.
|
|
if not buffer.value.endswith('$'):
|
|
user_name = buffer.value
|
|
else:
|
|
user_name = 'NT AUTHORITY\\NetworkService'
|
|
|
|
for path in sys.argv[1:]:
|
|
subprocess.call(['icacls', path, '/deny',
|
|
'{}:(RD)'.format(user_name)])
|
|
else:
|
|
for path in sys.argv[1:]:
|
|
subprocess.call(['chmod', 'a-r', path])
|