From eb6fa994383ebca1a96c6d1fdcb91405349bcdce Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Tue, 9 Nov 2021 17:15:24 -0800 Subject: [PATCH] Use path separator to split PSModulePath env var --- src/code/Utils.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 55b222571..e3cf92b2c 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -310,7 +310,7 @@ public static string GetInstalledPackageName(string pkgPath) if (File.Exists(pkgPath)) { // ex: ./PowerShell/Scripts/TestScript.ps1 - return System.IO.Path.GetFileNameWithoutExtension(pkgPath); + return Path.GetFileNameWithoutExtension(pkgPath); } else { @@ -335,19 +335,19 @@ public static List GetAllResourcePaths( if (scope is null) { string psModulePath = Environment.GetEnvironmentVariable("PSModulePath"); - resourcePaths.AddRange(psModulePath.Split(';').ToList()); + resourcePaths.AddRange(psModulePath.Split(Path.PathSeparator).ToList()); } if (scope is null || scope.Value is ScopeType.CurrentUser) { - resourcePaths.Add(System.IO.Path.Combine(myDocumentsPath, "Modules")); - resourcePaths.Add(System.IO.Path.Combine(myDocumentsPath, "Scripts")); + resourcePaths.Add(Path.Combine(myDocumentsPath, "Modules")); + resourcePaths.Add(Path.Combine(myDocumentsPath, "Scripts")); } if (scope is null || scope.Value is ScopeType.AllUsers) { - resourcePaths.Add(System.IO.Path.Combine(programFilesPath, "Modules")); - resourcePaths.Add(System.IO.Path.Combine(programFilesPath, "Scripts")); + resourcePaths.Add(Path.Combine(programFilesPath, "Modules")); + resourcePaths.Add(Path.Combine(programFilesPath, "Scripts")); } // resourcePaths should now contain, eg: @@ -405,13 +405,13 @@ public static List GetAllInstallationPaths(PSCmdlet psCmdlet, ScopeType var installationPaths = new List(); if (scope == ScopeType.AllUsers) { - installationPaths.Add(System.IO.Path.Combine(programFilesPath, "Modules")); - installationPaths.Add(System.IO.Path.Combine(programFilesPath, "Scripts")); + installationPaths.Add(Path.Combine(programFilesPath, "Modules")); + installationPaths.Add(Path.Combine(programFilesPath, "Scripts")); } else { - installationPaths.Add(System.IO.Path.Combine(myDocumentsPath, "Modules")); - installationPaths.Add(System.IO.Path.Combine(myDocumentsPath, "Scripts")); + installationPaths.Add(Path.Combine(myDocumentsPath, "Modules")); + installationPaths.Add(Path.Combine(myDocumentsPath, "Scripts")); } installationPaths = installationPaths.Distinct(StringComparer.InvariantCultureIgnoreCase).ToList(); @@ -435,8 +435,8 @@ private static void GetStandardPlatformPaths( else { // paths are the same for both Linux and macOS - myDocumentsPath = System.IO.Path.Combine(Environment.GetFolderPath(SpecialFolder.LocalApplicationData), "powershell"); - programFilesPath = System.IO.Path.Combine("/usr", "local", "share", "powershell"); + myDocumentsPath = Path.Combine(Environment.GetFolderPath(SpecialFolder.LocalApplicationData), "powershell"); + programFilesPath = Path.Combine("/usr", "local", "share", "powershell"); } }