internal CommandPathSearch( string commandName, LookupPathCollection lookupPaths, ExecutionContext context, Collection <string>?acceptableCommandNames, bool useFuzzyMatch) { _useFuzzyMatch = useFuzzyMatch; string[] commandPatterns; if (acceptableCommandNames != null) { // The name passed in is not a pattern. To minimize enumerating the file system, we // turn the command name into a pattern and then match against extensions in PATHEXT. // The old code would enumerate the file system many more times, once per possible extension. if (Platform.IsWindows) { commandPatterns = new[] { commandName + ".*" }; } else { // Porting note: on non-Windows platforms, we want to always allow just 'commandName' // as an acceptable command name. However, we also want to allow commands to be // called with the .ps1 extension, so that 'script.ps1' can be called by 'script'. commandPatterns = new[] { commandName, commandName + ".ps1" }; } _postProcessEnumeratedFiles = CheckAgainstAcceptableCommandNames; _acceptableCommandNames = acceptableCommandNames; } else { commandPatterns = new[] { commandName }; _postProcessEnumeratedFiles = JustCheckExtensions; } // Note, discovery must be set before resolving the current directory _context = context; _patterns = commandPatterns; _lookupPaths = lookupPaths; ResolveCurrentDirectoryInLookupPaths(); _orderedPathExt = CommandDiscovery.PathExtensionsWithPs1Prepended; // The same as in this.Reset() _lookupPathsEnumerator = _lookupPaths.GetEnumerator(); _patternEnumerator = _patterns.GetEnumerator(); _currentDirectoryResults = Array.Empty <string>(); _currentDirectoryResultsEnumerator = _currentDirectoryResults.GetEnumerator(); _justReset = true; }
internal IEnumerable<string> GetLookupDirectoryPaths() { LookupPathCollection paths = new LookupPathCollection(); string environmentVariable = Environment.GetEnvironmentVariable("PATH"); discoveryTracer.WriteLine("PATH: {0}", new object[] { environmentVariable }); if (((environmentVariable == null) || !string.Equals(this.pathCacheKey, environmentVariable, StringComparison.OrdinalIgnoreCase)) || (this.cachedPath == null)) { this.cachedLookupPaths = null; this.pathCacheKey = environmentVariable; if (this.pathCacheKey != null) { string[] strArray = this.pathCacheKey.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (strArray != null) { this.cachedPath = new Collection<string>(); foreach (string str2 in strArray) { string item = str2.TrimStart(new char[0]); this.cachedPath.Add(item); paths.Add(item); } } } } else { paths.AddRange(this.cachedPath); } if (this.cachedLookupPaths == null) { this.cachedLookupPaths = paths; } return this.cachedLookupPaths; }