Merge pull request #1282 from PowerShell/quoct/fixnugetprovider

Expose Platform API from SMA and uses that in NuGetProvider
This commit is contained in:
Quoc Truong
2016-07-06 12:15:59 -07:00
committed by GitHub
3 changed files with 45 additions and 5 deletions
@@ -171,6 +171,10 @@
// or $env:programfiles\NuGet\Packages\ if you are an admin.
try
{
#if LINUX
// there is only 1 installation location by default for linux ("HOME/.local/share/powershell/PackageManagement/NuGet/Packages")
string basePath = CurrentUserDefaultInstallLocation;
#else
var scope = (Scope == null) ? null : Scope.Value;
scope = string.IsNullOrWhiteSpace(scope) ? Constants.AllUsers : scope;
string basePath;
@@ -192,6 +196,7 @@
Constants.Messages.InstallRequiresCurrentUserScopeParameterForNonAdminUser, AllUserDefaultInstallLocation, CurrentUserDefaultInstallLocation);
return string.Empty;
}
#endif
if (!Directory.Exists(basePath))
{
@@ -215,7 +220,11 @@
get
{
#if CORECLR
#if LINUX
return Path.Combine(Path.GetDirectoryName(Platform.SelectProductNameForDirectory(Platform.XDG_Type.DATA)), "PackageManagement", "NuGet", "Packages");
#else
return Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "PackageManagement", "NuGet", "Packages");
#endif
#else
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PackageManagement", "NuGet", "Packages");
#endif
@@ -228,7 +237,11 @@
get
{
#if CORECLR
#if LINUX
return Path.Combine(Path.GetDirectoryName(Platform.SelectProductNameForDirectory(Platform.XDG_Type.DATA)), "PackageManagement", "NuGet", "Packages");
#else
return Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "NuGet", "Packages");
#endif
#else
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "NuGet", "Packages");
#endif
@@ -1289,7 +1302,11 @@
}
} else {
#if LINUX
var appdataFolder = Path.GetDirectoryName(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CONFIG));
#else
var appdataFolder = Environment.GetEnvironmentVariable("appdata");
#endif
_configurationFileLocation = Path.Combine(appdataFolder, "NuGet", NuGetConstant.SettingsFileName);
//create directory if does not exist
@@ -28,7 +28,7 @@ namespace System.Management.Automation
/// All these properties are calling into platform specific static classes, to make
/// sure the platform implementations are switched at runtime (including pinvokes).
/// </summary>
internal static class Platform
public static class Platform
{
// Platform variables used to defined corresponding PowerShell built-in variables
@@ -47,9 +47,15 @@ namespace System.Management.Automation
//enum for selecting the xdgpaths
public enum XDG_Type
{
PROFILE,
// location to store configuration file
CONFIG,
// location for powershell modules
MODULES,
// location to store temporary files
CACHE,
// location to store data that application needs
DATA,
// default location
DEFAULT
}
@@ -115,11 +121,12 @@ 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 xdgModuleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local", "share", "powershell", "Modules");
string xdgDataHomeDefault = Path.Combine( System.Environment.GetEnvironmentVariable("HOME"), ".local", "share", "powershell");
string xdgModuleDefault = Path.Combine ( xdgDataHomeDefault, "Modules");
string xdgCacheDefault = Path.Combine (System.Environment.GetEnvironmentVariable("HOME"), ".cache", "powershell");
switch (dirpath){
case Platform.XDG_Type.PROFILE:
case Platform.XDG_Type.CONFIG:
//the user has set XDG_CONFIG_HOME corrresponding to profile path
if (String.IsNullOrEmpty(xdgconfighome))
{
@@ -132,6 +139,22 @@ namespace System.Management.Automation
return Path.Combine(xdgconfighome, "powershell");
}
case Platform.XDG_Type.DATA:
//the user has set XDG_DATA_HOME corresponding to module path
if (String.IsNullOrEmpty(xdgdatahome)){
// create the xdg folder if needed
if (!Directory.Exists(xdgDataHomeDefault))
{
Directory.CreateDirectory(xdgDataHomeDefault);
}
return xdgDataHomeDefault;
}
else
{
return Path.Combine(xdgdatahome, "powershell");
}
case Platform.XDG_Type.MODULES:
//the user has set XDG_DATA_HOME corresponding to module path
if (String.IsNullOrEmpty(xdgdatahome)){
@@ -607,7 +607,7 @@ namespace System.Management.Automation
/// Profile uses this to control profile loading.
/// </remarks>
internal static string ProductNameForDirectory =
Platform.IsWindows ? "WindowsPowerShell" : Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE);
Platform.IsWindows ? "WindowsPowerShell" : Platform.SelectProductNameForDirectory(Platform.XDG_Type.CONFIG);
/// <summary>
/// The name of the subdirectory that contains packages.