internal static IEnumerable <FileSystemInfo> CreateFileSystemInfoIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption) { SearchResultHandler <FileSystemInfo> resultHandler = (SearchResultHandler <FileSystemInfo>) new FileSystemInfoResultHandler(); return((IEnumerable <FileSystemInfo>) new FileSystemEnumerableIterator <FileSystemInfo>(path, originalUserPath, searchPattern, searchOption, resultHandler, true)); }
private Win32FileSystemEnumerableIterator(string fullPath, string normalizedSearchPath, string searchCriteria, string userPath, SearchOption searchOption, SearchResultHandler <TSource> resultHandler) { _fullPath = fullPath; _normalizedSearchPath = normalizedSearchPath; _searchCriteria = searchCriteria; _resultHandler = resultHandler; _userPath = userPath; _searchOption = searchOption; if (searchCriteria != null) { PathInternal.CheckInvalidPathChars(fullPath); if (PathInternal.HasWildCardCharacters(fullPath)) { throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(fullPath)); } _searchData = new PathPair(userPath, normalizedSearchPath); CommonInit(); } else { _empty = true; } }
internal static IEnumerable <string> CreateFileNameIterator(string path, string originalUserPath, string searchPattern, bool includeFiles, bool includeDirs, SearchOption searchOption, bool checkHost) { SearchResultHandler <string> resultHandler = (SearchResultHandler <string>) new StringResultHandler(includeFiles, includeDirs); return((IEnumerable <string>) new FileSystemEnumerableIterator <string>(path, originalUserPath, searchPattern, searchOption, resultHandler, checkHost)); }
private FileSystemEnumerableIterator(String fullPath, String normalizedSearchPath, String searchCriteria, String userPath, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost) { this.fullPath = fullPath; this.normalizedSearchPath = normalizedSearchPath; this.searchCriteria = searchCriteria; this._resultHandler = resultHandler; this.userPath = userPath; this.searchOption = searchOption; this._checkHost = checkHost; searchStack = new List <Directory.SearchData>(); if (searchCriteria != null) { // permission demands String[] demandPaths = new String[2]; // Any illegal chars such as *, ? will be caught by FileIOPermission.HasIllegalCharacters demandPaths[0] = Directory.GetDemandDir(fullPath, true); // For filters like foo\*.cs we need to verify if the directory foo is not denied access. // Do a demand on the combined path so that we can fail early in case of deny demandPaths[1] = Directory.GetDemandDir(normalizedSearchPath, true); #if FEATURE_CORECLR if (checkHost) { FileSecurityState state1 = new FileSecurityState(FileSecurityStateAccess.PathDiscovery, String.Empty, demandPaths[0]); state1.EnsureState(); FileSecurityState state2 = new FileSecurityState(FileSecurityStateAccess.PathDiscovery, String.Empty, demandPaths[1]); state2.EnsureState(); } #else new FileIOPermission(FileIOPermissionAccess.PathDiscovery, demandPaths, false, false).Demand(); #endif searchData = new Directory.SearchData(normalizedSearchPath, userPath, searchOption); CommonInit(); } else { empty = true; } }
internal Win32FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler) { Debug.Assert(path != null); Debug.Assert(originalUserPath != null); Debug.Assert(searchPattern != null); Debug.Assert(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly); Debug.Assert(resultHandler != null); _oldMode = Interop.mincore.SetErrorMode(Interop.mincore.SEM_FAILCRITICALERRORS); string normalizedSearchPattern = PathHelpers.NormalizeSearchPattern(searchPattern); if (normalizedSearchPattern.Length == 0) { _empty = true; } else { _resultHandler = resultHandler; _searchOption = searchOption; _fullPath = Path.GetFullPath(path); string fullSearchString = PathHelpers.GetFullSearchString(_fullPath, normalizedSearchPattern); _normalizedSearchPath = Path.GetDirectoryName(fullSearchString); // normalize search criteria _searchCriteria = GetNormalizedSearchCriteria(fullSearchString, _normalizedSearchPath); // fix up user path string searchPatternDirName = Path.GetDirectoryName(normalizedSearchPattern); _userPath = string.IsNullOrEmpty(searchPatternDirName) ? originalUserPath : Path.Combine(originalUserPath, searchPatternDirName); _searchData = new PathPair(_userPath, _normalizedSearchPath); CommonInit(); } }
private FileSystemEnumerableIterator(string fullPath, string normalizedSearchPath, string searchCriteria, string userPath, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost) { this.fullPath = fullPath; this.normalizedSearchPath = normalizedSearchPath; this.searchCriteria = searchCriteria; this._resultHandler = resultHandler; this.userPath = userPath; this.searchOption = searchOption; this._checkHost = checkHost; this.searchStack = new List <Directory.SearchData>(); if (searchCriteria != null) { new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[2] { Directory.GetDemandDir(fullPath, true), Directory.GetDemandDir(normalizedSearchPath, true) }, false, false).Demand(); this.searchData = new Directory.SearchData(normalizedSearchPath, userPath, searchOption); this.CommonInit(); } else { this.empty = true; } }
internal FileSystemEnumerableIterator(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost) { Contract.Requires(path != null); Contract.Requires(originalUserPath != null); Contract.Requires(searchPattern != null); Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly); Contract.Requires(resultHandler != null); oldMode = Win32Native.SetErrorMode(Win32Native.SEM_FAILCRITICALERRORS); searchStack = new List <Directory.SearchData>(); String normalizedSearchPattern = NormalizeSearchPattern(searchPattern); if (normalizedSearchPattern.Length == 0) { empty = true; } else { _resultHandler = resultHandler; this.searchOption = searchOption; fullPath = Path.GetFullPath(path); String fullSearchString = GetFullSearchString(fullPath, normalizedSearchPattern); normalizedSearchPath = Path.GetDirectoryName(fullSearchString); // permission demands String[] demandPaths = new String[2]; // Any illegal chars such as *, ? will be caught by FileIOPermission.HasIllegalCharacters demandPaths[0] = Directory.GetDemandDir(fullPath, true); // For filters like foo\*.cs we need to verify if the directory foo is not denied access. // Do a demand on the combined path so that we can fail early in case of deny demandPaths[1] = Directory.GetDemandDir(normalizedSearchPath, true); _checkHost = checkHost; #if FEATURE_CORECLR if (checkHost) { FileSecurityState state1 = new FileSecurityState(FileSecurityStateAccess.PathDiscovery, String.Empty, demandPaths[0]); state1.EnsureState(); FileSecurityState state2 = new FileSecurityState(FileSecurityStateAccess.PathDiscovery, String.Empty, demandPaths[1]); state2.EnsureState(); } #else new FileIOPermission(FileIOPermissionAccess.PathDiscovery, demandPaths, false, false).Demand(); #endif // normalize search criteria searchCriteria = GetNormalizedSearchCriteria(fullSearchString, normalizedSearchPath); // fix up user path String searchPatternDirName = Path.GetDirectoryName(normalizedSearchPattern); String userPathTemp = originalUserPath; if (searchPatternDirName != null && searchPatternDirName.Length != 0) { userPathTemp = Path.Combine(userPathTemp, searchPatternDirName); } this.userPath = userPathTemp; searchData = new Directory.SearchData(normalizedSearchPath, this.userPath, searchOption); CommonInit(); } }
internal FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost) { this.oldMode = Win32Native.SetErrorMode(1); this.searchStack = new List <Directory.SearchData>(); string str = FileSystemEnumerableIterator <TSource> .NormalizeSearchPattern(searchPattern); if (str.Length == 0) { this.empty = true; } else { this._resultHandler = resultHandler; this.searchOption = searchOption; this.fullPath = Path.GetFullPathInternal(path); string fullSearchString = FileSystemEnumerableIterator <TSource> .GetFullSearchString(this.fullPath, str); this.normalizedSearchPath = Path.GetDirectoryName(fullSearchString); string[] pathList = new string[2] { Directory.GetDemandDir(this.fullPath, true), Directory.GetDemandDir(this.normalizedSearchPath, true) }; this._checkHost = checkHost; new FileIOPermission(FileIOPermissionAccess.PathDiscovery, pathList, false, false).Demand(); this.searchCriteria = FileSystemEnumerableIterator <TSource> .GetNormalizedSearchCriteria(fullSearchString, this.normalizedSearchPath); string directoryName = Path.GetDirectoryName(str); string path1 = originalUserPath; if (directoryName != null && directoryName.Length != 0) { path1 = Path.Combine(path1, directoryName); } this.userPath = path1; this.searchData = new Directory.SearchData(this.normalizedSearchPath, this.userPath, searchOption); this.CommonInit(); } }
private FileSystemEnumerableIterator(String fullPath, String normalizedSearchPath, String searchCriteria, String userPath, SearchOption searchOption, SearchResultHandler <TSource> resultHandler) { this.fullPath = fullPath; this.normalizedSearchPath = normalizedSearchPath; this.searchCriteria = searchCriteria; this._resultHandler = resultHandler; this.userPath = userPath; this.searchOption = searchOption; searchStack = new List <Directory.SearchData>(); if (searchCriteria != null) { searchData = new Directory.SearchData(normalizedSearchPath, userPath, searchOption); CommonInit(); } else { empty = true; } }
internal FileSystemEnumerableIterator(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost) { Debug.Assert(path != null); Debug.Assert(originalUserPath != null); Debug.Assert(searchPattern != null); Debug.Assert(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly); Debug.Assert(resultHandler != null); #if !PLATFORM_UNIX _setBackOldMode = Interop.Kernel32.SetThreadErrorMode(Interop.Kernel32.SEM_FAILCRITICALERRORS, out _oldMode); #endif searchStack = new List <Directory.SearchData>(); String normalizedSearchPattern = NormalizeSearchPattern(searchPattern); if (normalizedSearchPattern.Length == 0) { empty = true; } else { _resultHandler = resultHandler; this.searchOption = searchOption; fullPath = Path.GetFullPath(path); String fullSearchString = GetFullSearchString(fullPath, normalizedSearchPattern); normalizedSearchPath = Path.GetDirectoryName(fullSearchString); // normalize search criteria searchCriteria = GetNormalizedSearchCriteria(fullSearchString, normalizedSearchPath); // fix up user path String searchPatternDirName = Path.GetDirectoryName(normalizedSearchPattern); String userPathTemp = originalUserPath; if (searchPatternDirName != null && searchPatternDirName.Length != 0) { userPathTemp = Path.Combine(userPathTemp, searchPatternDirName); } this.userPath = userPathTemp; searchData = new Directory.SearchData(normalizedSearchPath, this.userPath, searchOption); CommonInit(); } }
private Win32FileSystemEnumerableIterator(String fullPath, String normalizedSearchPath, String searchCriteria, String userPath, SearchOption searchOption, SearchResultHandler <TSource> resultHandler) { this._fullPath = fullPath; this._normalizedSearchPath = normalizedSearchPath; this._searchCriteria = searchCriteria; this._resultHandler = resultHandler; this._userPath = userPath; this._searchOption = searchOption; _searchStack = new List <Directory.SearchData>(); if (searchCriteria != null) { PathHelpers.CheckInvalidPathChars(fullPath, true); _searchData = new Directory.SearchData(normalizedSearchPath, userPath, searchOption); CommonInit(); } else { _empty = true; } }
internal Win32FileSystemEnumerableIterator(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler) { Contract.Requires(path != null); Contract.Requires(originalUserPath != null); Contract.Requires(searchPattern != null); Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly); Contract.Requires(resultHandler != null); _oldMode = Interop.mincore.SetErrorMode(Interop.SEM_FAILCRITICALERRORS); _searchStack = new List <Directory.SearchData>(); String normalizedSearchPattern = NormalizeSearchPattern(searchPattern); if (normalizedSearchPattern.Length == 0) { _empty = true; } else { _resultHandler = resultHandler; this._searchOption = searchOption; _fullPath = Path.GetFullPath(path); String fullSearchString = GetFullSearchString(_fullPath, normalizedSearchPattern); _normalizedSearchPath = Path.GetDirectoryName(fullSearchString); // normalize search criteria _searchCriteria = GetNormalizedSearchCriteria(fullSearchString, _normalizedSearchPath); // fix up user path String searchPatternDirName = Path.GetDirectoryName(normalizedSearchPattern); String userPathTemp = originalUserPath; if (searchPatternDirName != null && searchPatternDirName.Length != 0) { userPathTemp = Path.Combine(userPathTemp, searchPatternDirName); } this._userPath = userPathTemp; _searchData = new Directory.SearchData(_normalizedSearchPath, this._userPath, searchOption); CommonInit(); } }