From b9d8759c68c8070bf4a8722da5b368ec3af42206 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 23 Jun 2016 13:45:38 -0500 Subject: [PATCH] (GH-826) SYSTEM user always uses machine TEMP Using `Path.GetTempPath()` instead of `Environment.GetEnvironmentVariable("TEMP")` in 76ae7e2f7 for GH-532 has caused the SYSTEM user to return one of the following: * `c:\windows\system32\config\systemprofile\appdata\local\temp` * `c:\windows\syswow64\config\systemprofile\appdata\local\temp` These folders seem to cause issues with accessing files, causing all kinds of fun issues, such as "Not able to read package from path" and not able to find executables being downloaded to these folders. If one of these two folders is detected, ensure that the folder structure is `%SystemRoot%\TEMP`. --- .../infrastructure.app/ApplicationParameters.cs | 2 ++ .../infrastructure/filesystem/DotNetFileSystem.cs | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 8c062983eb..0866dc8a26 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -76,6 +76,8 @@ public static class Environment public static readonly string Path = "Path"; public static readonly string PathExtensions = "PATHEXT"; public static readonly string PsModulePath = "PSModulePath"; + public static readonly string Temp = "TEMP"; + public static readonly string SystemUserName = "SYSTEM"; public static readonly string Username = "USERNAME"; public static readonly string ProcessorArchitecture = "PROCESSOR_ARCHITECTURE"; public static readonly string EnvironmentSeparator = ";"; diff --git a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs index 2fa64bea5c..89167de4ee 100644 --- a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs +++ b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs @@ -94,7 +94,14 @@ public string get_full_path(string path) public string get_temp_path() { - return Path.GetTempPath(); + var path = Path.GetTempPath(); + + if (System.Environment.UserName.contains(ApplicationParameters.Environment.SystemUserName) || path.contains("config\\systemprofile\\appdata")) + { + path = System.Environment.ExpandEnvironmentVariables(System.Environment.GetEnvironmentVariable(ApplicationParameters.Environment.Temp, EnvironmentVariableTarget.Machine).to_string()); + } + + return path; } public char get_path_directory_separator_char()