commit c3b8d305ec5d039af8a3d1553f26548cdc2c208d
parent 854750e29736d96c314630a2b259a1ec19aa4339
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Thu, 10 Jun 2021 13:39:40 -0700
Move Temp path to the user's location (#1146)
Move the temp directory that is used from the package specific temp to the user's temp location. This should prevent the Mandatory Low ACL that was apparently causing #189 from being inherited. While this is more avoiding the problem than fixing it, given the relatively low rate of occurrence it might be hard to ensure that it was truly fixed by actually changing the ACLs (and would require much more time and code to write).
Additionally changes the behavior of `Runtime::GetPathTo` to delete non-directories when they are encountered rather than just erroring directly.
Diffstat:
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/AppInstallerCommonCore/Runtime.cpp b/src/AppInstallerCommonCore/Runtime.cpp
@@ -88,6 +88,16 @@ namespace AppInstaller::Runtime
return knownFolder.get();
}
+ // Gets the user's temp path
+ std::filesystem::path GetPathToUserTemp()
+ {
+ wchar_t tempPath[MAX_PATH + 1];
+ DWORD tempChars = GetTempPathW(ARRAYSIZE(tempPath), tempPath);
+ THROW_LAST_ERROR_IF(!tempChars);
+ THROW_HR_IF(E_UNEXPECTED, tempChars > ARRAYSIZE(tempPath));
+ return { std::wstring_view{ tempPath, static_cast<size_t>(tempChars) } };
+ }
+
// Gets the path to the appdata root.
// *Only used by non packaged version!*
std::filesystem::path GetPathToAppDataRoot()
@@ -225,8 +235,10 @@ namespace AppInstaller::Runtime
switch (path)
{
case PathName::Temp:
- result.assign(appStorage.TemporaryFolder().Path().c_str());
+ {
+ result = GetPathToUserTemp();
result /= s_DefaultTempDirectory;
+ }
break;
case PathName::LocalState:
case PathName::UserFileSettings:
@@ -297,16 +309,14 @@ namespace AppInstaller::Runtime
case PathName::Temp:
case PathName::DefaultLogLocation:
{
- wchar_t tempPath[MAX_PATH + 1];
- DWORD tempChars = GetTempPathW(ARRAYSIZE(tempPath), tempPath);
- result.assign(std::wstring_view{ tempPath, static_cast<size_t>(tempChars) });
-
+ result = GetPathToUserTemp();
result /= s_DefaultTempDirectory;
}
break;
case PathName::DefaultLogLocationForDisplay:
result.assign("%TEMP%");
result /= s_DefaultTempDirectory;
+ create = false;
break;
case PathName::LocalState:
result = GetPathToAppDataDir(s_AppDataDir_State);
@@ -343,18 +353,12 @@ namespace AppInstaller::Runtime
if (create && result.is_absolute())
{
- if (std::filesystem::exists(result))
- {
- if (!std::filesystem::is_directory(result))
- {
- // STATUS_NOT_A_DIRECTORY: A requested opened file is not a directory.
- THROW_NTSTATUS_MSG(0xC0000103, "Location is not a directory");
- }
- }
- else
+ if (std::filesystem::exists(result) && !std::filesystem::is_directory(result))
{
- std::filesystem::create_directories(result);
+ std::filesystem::remove(result);
}
+
+ std::filesystem::create_directories(result);
}
return result;