GeezerVison is showing github.com — gh-134587: Suggest fix for tempfile.mkdtemp() in Windows AppContainer by vedant713 · Pull Request #134607 · python/cpython
Conversation
vedant713
commented
May 24, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Proposed Solution
- Detect whether the process is running inside an AppContainer.
- Retrieve the AppContainer SID using
whoami /user.
- Use
icacls to grant Full Control access to that SID for the created directory.
Suggested Helper Functions
if _os.name == 'nt':
import ctypes as _ctypes
import ctypes.wintypes as _wintypes
import subprocess as _subprocess
def _is_appcontainer():
TOKEN_QUERY = 0x0008
TokenIsAppContainer = 29
h_token = _wintypes.HANDLE()
if not _ctypes.windll.advapi32.OpenProcessToken(
_ctypes.windll.kernel32.GetCurrentProcess(),
TOKEN_QUERY,
_ctypes.byref(h_token)
):
return False
is_container = _wintypes.BOOL()
return_length = _wintypes.DWORD()
if not _ctypes.windll.advapi32.GetTokenInformation(
h_token,
TokenIsAppContainer,
_ctypes.byref(is_container),
_ctypes.sizeof(is_container),
_ctypes.byref(return_length)
):
return False
return bool(is_container.value)
def _grant_appcontainer_access(path):
try:
sid = _subprocess.check_output("whoami /user", shell=True)
sid_str = sid.decode().splitlines()[1].split()[1]
_subprocess.run(f'icacls \"{path}\" /grant *{sid_str}:(OI)(CI)F', shell=True, check=True)
except Exception:
pass
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
stale
Stale PR or inactive for long period of time.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.