mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Changing history to cache, removed redundant code
This commit is contained in:
committed by
Andrew Schwartzmeyer
parent
c2527199a6
commit
caa4c3f163
@@ -187,17 +187,18 @@ namespace Microsoft.PowerShell
|
||||
@"\Microsoft\Windows\PowerShell";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
//check if the user has set an XDG path in their environment variables
|
||||
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(profileDir)) //xdg value may have been set but not a valid directory
|
||||
{
|
||||
Console.WriteLine("The selected directory (" + profileDir +") for the profile does not exist. Using the default path.");
|
||||
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.DEFAULT);
|
||||
}
|
||||
else
|
||||
{
|
||||
//check if the user has set an XDG path in their environment variables
|
||||
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE);
|
||||
|
||||
if (!Directory.Exists(profileDir)) //xdg value may have been set but not a valid directory
|
||||
{
|
||||
Console.Error.WriteLine("The selected directory (" + profileDir +") for the profile does not exist. Using the default path.");
|
||||
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ClrFacade.SetProfileOptimizationRoot(profileDir);
|
||||
}
|
||||
|
||||
@@ -180,23 +180,20 @@ namespace Microsoft.PowerShell
|
||||
else
|
||||
{
|
||||
//PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately
|
||||
string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
string historypath = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
|
||||
|
||||
if (!String.IsNullOrEmpty(historypath))
|
||||
{
|
||||
historypath = System.IO.Path.Combine(historypath, "powershell");
|
||||
historypath = System.IO.Path.Combine(historypath, "powershell", "PSReadLine", hostName + "_history.txt");
|
||||
HistorySavePath = historypath;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
historypath = System.IO.Path.Combine(
|
||||
Environment.GetEnvironmentVariable("HOME"),
|
||||
".local/share/powershell/modules");
|
||||
|
||||
HistorySavePath = System.IO.Path.Combine(
|
||||
Environment.GetEnvironmentVariable("HOME"),
|
||||
historypath,
|
||||
".cache",
|
||||
"powershell",
|
||||
"PSReadLine",
|
||||
hostName + "_history.txt");
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
PROFILE,
|
||||
MODULES,
|
||||
HISTORY,
|
||||
CACHE,
|
||||
DEFAULT
|
||||
|
||||
}
|
||||
@@ -115,7 +115,8 @@ namespace System.Management.Automation
|
||||
string xdgdatahome = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
string xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
|
||||
string xdgConfigHomeDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config/powershell");
|
||||
string moduleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local/share/powershell/modules");
|
||||
string xdgModuleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local/share/powershell/modules");
|
||||
string xdgCacheDefault = Path.Combine (System.Environment.GetEnvironmentVariable("HOME"), ".cache/powershell");
|
||||
|
||||
switch (dirpath){
|
||||
case Platform.XDG_Type.PROFILE:
|
||||
@@ -134,40 +135,54 @@ namespace System.Management.Automation
|
||||
case Platform.XDG_Type.MODULES:
|
||||
//the user has set XDG_DATA_HOME corresponding to module path
|
||||
if (String.IsNullOrEmpty(xdgdatahome)){
|
||||
//xdg values have not been set
|
||||
if (!Directory.Exists(moduleDefault)) //module folder not always guaranteed to exist
|
||||
{
|
||||
Directory.CreateDirectory(moduleDefault);
|
||||
}
|
||||
|
||||
return xdgConfigHomeDefault;
|
||||
|
||||
//xdg values have not been set
|
||||
if (!Directory.Exists(xdgModuleDefault)) //module folder not always guaranteed to exist
|
||||
{
|
||||
Directory.CreateDirectory(xdgModuleDefault);
|
||||
}
|
||||
return xdgConfigHomeDefault;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return Path.Combine(xdgdatahome, "powershell");
|
||||
}
|
||||
|
||||
case Platform.XDG_Type.HISTORY:
|
||||
|
||||
case Platform.XDG_Type.CACHE:
|
||||
//the user has set XDG_CACHE_HOME
|
||||
if (String.IsNullOrEmpty(xdgcachehome)){
|
||||
return xdgConfigHomeDefault;
|
||||
if (String.IsNullOrEmpty(xdgcachehome))
|
||||
{
|
||||
//xdg values have not been set
|
||||
if (!Directory.Exists(xdgCacheDefault)) //module folder not always guaranteed to exist
|
||||
{
|
||||
Directory.CreateDirectory(xdgCacheDefault);
|
||||
}
|
||||
|
||||
return xdgCacheDefault;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(xdgcachehome, "powershell");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case Platform.XDG_Type.DEFAULT:
|
||||
//default for profile location
|
||||
return xdgConfigHomeDefault;
|
||||
|
||||
default:
|
||||
//xdgConfigHomeDefault needs to be created in the edge case that we do not have the folder or it was deleted
|
||||
//This folder is the default in the event of all other failures for data storage
|
||||
if (!Directory.Exists(xdgConfigHomeDefault))
|
||||
{
|
||||
Directory.CreateDirectory(xdgConfigHomeDefault);
|
||||
try {
|
||||
Directory.CreateDirectory(xdgConfigHomeDefault);
|
||||
}
|
||||
catch{
|
||||
|
||||
Console.Error.WriteLine("Failed to create default data directory: " + xdgConfigHomeDefault);
|
||||
}
|
||||
}
|
||||
|
||||
return xdgConfigHomeDefault;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,11 +188,6 @@ namespace System.Management.Automation
|
||||
basePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
basePath = IO.Path.Combine(basePath, Utils.ProductNameForDirectory);
|
||||
|
||||
//If the profile path doesn't exist, create it.
|
||||
if (!System.IO.Directory.Exists(basePath))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(basePath);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user