Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(service): make Windows API access type-check portable
  • Loading branch information
Alanxtl committed Sep 3, 2026
commit a32714beb9ae0051f40751d4bbe87cbee635bead
8 changes: 5 additions & 3 deletions src/powercontext/service/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def _windows_file_owner_sid(path: Path) -> str:
security_descriptor = ctypes.c_void_p()
local_free: Any = None
try:
win_dll = ctypes.WinDLL
win_dll = getattr(ctypes, "WinDLL") # noqa: B009
win_error = getattr(ctypes, "WinError") # noqa: B009
get_last_error = getattr(ctypes, "get_last_error") # noqa: B009
advapi32 = win_dll("Advapi32", use_last_error=True)
kernel32 = win_dll("Kernel32", use_last_error=True)
local_free = kernel32.LocalFree
Expand Down Expand Up @@ -217,14 +219,14 @@ def _windows_file_owner_sid(path: Path) -> str:
ctypes.byref(security_descriptor),
)
if error_code:
raise ctypes.WinError(error_code)
raise win_error(error_code)

convert_sid = advapi32.ConvertSidToStringSidW
convert_sid.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_wchar_p)]
convert_sid.restype = ctypes.c_int
owner_text = ctypes.c_wchar_p()
if not convert_sid(owner, ctypes.byref(owner_text)) or owner_text.value is None:
raise ctypes.WinError(ctypes.get_last_error())
raise win_error(get_last_error())
try:
return owner_text.value
finally:
Expand Down
Loading