Skip to content

Commit

Permalink
gh-115049: Fix py.exe failing when user has no LocalAppData. (GH-115185)
Browse files Browse the repository at this point in the history
Also ensure we always display a debug message or error for RC_INTERNAL_ERROR
  • Loading branch information
zooba committed Feb 12, 2024
1 parent 91bf01d commit c39272e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes ``py.exe`` launcher failing when run as users without user profiles.
15 changes: 13 additions & 2 deletions PC/launcher2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ _registryReadLegacyEnvironment(const SearchInfo *search, HKEY root, EnvironmentI

int count = swprintf_s(realTag, tagLength + 4, L"%s-32", env->tag);
if (count == -1) {
debug(L"# Failed to generate 32bit tag\n");
free(realTag);
return RC_INTERNAL_ERROR;
}
Expand Down Expand Up @@ -1749,10 +1750,18 @@ appxSearch(const SearchInfo *search, EnvironmentInfo **result, const wchar_t *pa
exeName = search->windowed ? L"pythonw.exe" : L"python.exe";
}

if (FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buffer)) ||
!join(buffer, MAXLEN, L"Microsoft\\WindowsApps") ||
// Failure to get LocalAppData may just mean we're running as a user who
// doesn't have a profile directory.
// In this case, return "not found", but don't fail.
// Chances are they can't launch Store installs anyway.
if (FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buffer))) {
return RC_NO_PYTHON;
}

if (!join(buffer, MAXLEN, L"Microsoft\\WindowsApps") ||
!join(buffer, MAXLEN, packageFamilyName) ||
!join(buffer, MAXLEN, exeName)) {
debug(L"# Failed to construct App Execution Alias path\n");
return RC_INTERNAL_ERROR;
}

Expand Down Expand Up @@ -1982,6 +1991,7 @@ collectEnvironments(const SearchInfo *search, EnvironmentInfo **result)
EnvironmentInfo *env = NULL;

if (!result) {
debug(L"# collectEnvironments() was passed a NULL result\n");
return RC_INTERNAL_ERROR;
}
*result = NULL;
Expand Down Expand Up @@ -2276,6 +2286,7 @@ int
selectEnvironment(const SearchInfo *search, EnvironmentInfo *root, EnvironmentInfo **best)
{
if (!best) {
debug(L"# selectEnvironment() was passed a NULL best\n");
return RC_INTERNAL_ERROR;
}
if (!root) {
Expand Down

0 comments on commit c39272e

Please sign in to comment.