Update the job cache location on on windows platforms (#1740)

* Update the job cache location on non-windows platforms
This commit is contained in:
chunqingchen 2016-08-12 16:54:05 -07:00 committed by Jason Shirk
parent 585b83387c
commit 2764b31c07
2 changed files with 19 additions and 5 deletions

View file

@ -424,8 +424,11 @@ namespace Microsoft.PowerShell.ScheduledJob
/// <returns>Directory Path</returns> /// <returns>Directory Path</returns>
public static string GetJobDefinitionLocation() public static string GetJobDefinitionLocation()
{ {
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), #if UNIX
ScheduledJobsPath); return Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), "ScheduledJobs"));
#else
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ScheduledJobsPath);
#endif
} }
public static void CreateDirectoryIfNotExists() public static void CreateDirectoryIfNotExists()
@ -444,9 +447,12 @@ namespace Microsoft.PowerShell.ScheduledJob
/// <returns>Directory Path</returns> /// <returns>Directory Path</returns>
private static string GetDirectoryPath() private static string GetDirectoryPath()
{ {
string pathName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), string pathName;
ScheduledJobsPath); #if UNIX
pathName = Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), "ScheduledJobs"));
#else
pathName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ScheduledJobsPath);
#endif
if (!Directory.Exists(pathName)) if (!Directory.Exists(pathName))
{ {
Directory.CreateDirectory(pathName); Directory.CreateDirectory(pathName);
@ -499,9 +505,13 @@ namespace Microsoft.PowerShell.ScheduledJob
/// <returns>Directory Path</returns> /// <returns>Directory Path</returns>
private static string GetJobDefinitionPath(string definitionName) private static string GetJobDefinitionPath(string definitionName)
{ {
#if UNIX
return Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), "ScheduledJobs", definitionName);
#else
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
ScheduledJobsPath, ScheduledJobsPath,
definitionName); definitionName);
#endif
} }
/// <summary> /// <summary>

View file

@ -3106,10 +3106,14 @@ namespace System.Management.Automation.Runspaces
// Or for virtual accounts // Or for virtual accounts
// WinDir\System32\Microsoft\Windows\PowerShell\DriveRoots\[UserName] // WinDir\System32\Microsoft\Windows\PowerShell\DriveRoots\[UserName]
string directoryName = MakeUserNamePath(); string directoryName = MakeUserNamePath();
#if UNIX
string userDrivePath = Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), "DriveRoots", directoryName);
#else
string userDrivePath = Path.Combine( string userDrivePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
@"Microsoft\Windows\PowerShell\DriveRoots", @"Microsoft\Windows\PowerShell\DriveRoots",
directoryName); directoryName);
#endif
// Create directory if it doesn't exist. // Create directory if it doesn't exist.
if (!System.IO.Directory.Exists(userDrivePath)) if (!System.IO.Directory.Exists(userDrivePath))