Skip to content

Commit

Permalink
(GH-826) SYSTEM user always uses machine TEMP
Browse files Browse the repository at this point in the history
Using `Path.GetTempPath()` instead of
`Environment.GetEnvironmentVariable("TEMP")` in 76ae7e2 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`.
  • Loading branch information
ferventcoder committed Jun 23, 2016
1 parent d6c7fc8 commit b9d8759
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ";";
Expand Down
9 changes: 8 additions & 1 deletion src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b9d8759

Please sign in to comment.