| |
| |
|
|
| using System.Buffers; |
| using System.Collections.Generic; |
| using System.Diagnostics.CodeAnalysis; |
| using System.Globalization; |
| using System.IO; |
| using System.Management.Automation.Internal; |
| using System.Management.Automation.Runspaces; |
| using System.Runtime.CompilerServices; |
| using System.Text; |
| using Microsoft.PowerShell.Commands; |
| using Dbg = System.Management.Automation.Diagnostics; |
|
|
| namespace System.Management.Automation |
| { |
| |
| |
| |
| internal static class PathUtils |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| internal static void MasterStreamOpen( |
| PSCmdlet cmdlet, |
| string filePath, |
| string encoding, |
| bool defaultEncoding, |
| bool Append, |
| bool Force, |
| bool NoClobber, |
| out FileStream fileStream, |
| out StreamWriter streamWriter, |
| out FileInfo readOnlyFileInfo, |
| bool isLiteralPath |
| ) |
| { |
| Encoding resolvedEncoding = EncodingConversion.Convert(cmdlet, encoding); |
|
|
| MasterStreamOpen(cmdlet, filePath, resolvedEncoding, defaultEncoding, Append, Force, NoClobber, out fileStream, out streamWriter, out readOnlyFileInfo, isLiteralPath); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| internal static void MasterStreamOpen( |
| PSCmdlet cmdlet, |
| string filePath, |
| Encoding resolvedEncoding, |
| bool defaultEncoding, |
| bool Append, |
| bool Force, |
| bool NoClobber, |
| out FileStream fileStream, |
| out StreamWriter streamWriter, |
| out FileInfo readOnlyFileInfo, |
| bool isLiteralPath) |
| { |
| fileStream = null; |
| streamWriter = null; |
| readOnlyFileInfo = null; |
| string resolvedPath = ResolveFilePath(filePath, cmdlet, isLiteralPath); |
| try |
| { |
| MasterStreamOpenImpl( |
| resolvedPath, |
| resolvedEncoding, |
| defaultEncoding, |
| Append, |
| Force, |
| NoClobber, |
| out fileStream, |
| out streamWriter, |
| out readOnlyFileInfo); |
| } |
| |
| catch (ArgumentException e) |
| { |
| |
| ReportFileOpenFailure(cmdlet, resolvedPath, e); |
| } |
| catch (IOException e) |
| { |
| if (NoClobber && File.Exists(resolvedPath)) |
| { |
| |
| ErrorRecord errorRecord = new( |
| e, "NoClobber", ErrorCategory.ResourceExists, resolvedPath); |
| errorRecord.ErrorDetails = new ErrorDetails( |
| cmdlet, |
| "PathUtilsStrings", |
| "UtilityFileExistsNoClobber", |
| filePath, |
| "NoClobber"); |
|
|
| |
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
| |
| ReportFileOpenFailure(cmdlet, resolvedPath, e); |
| } |
| catch (UnauthorizedAccessException e) |
| { |
| |
| ReportFileOpenFailure(cmdlet, resolvedPath, e); |
| } |
| catch (NotSupportedException e) |
| { |
| |
| ReportFileOpenFailure(cmdlet, resolvedPath, e); |
| } |
| catch (System.Security.SecurityException e) |
| { |
| |
| ReportFileOpenFailure(cmdlet, resolvedPath, e); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| internal static void MasterStreamOpen( |
| string filePath, |
| Encoding resolvedEncoding, |
| bool defaultEncoding, |
| bool Append, |
| bool Force, |
| bool NoClobber, |
| out FileStream fileStream, |
| out StreamWriter streamWriter, |
| out FileInfo readOnlyFileInfo, |
| bool isLiteralPath) |
| { |
| fileStream = null; |
| streamWriter = null; |
| readOnlyFileInfo = null; |
| string resolvedPath = ResolveFilePath(filePath, isLiteralPath); |
| try |
| { |
| MasterStreamOpenImpl( |
| resolvedPath, |
| resolvedEncoding, |
| defaultEncoding, |
| Append, |
| Force, |
| NoClobber, |
| out fileStream, |
| out streamWriter, |
| out readOnlyFileInfo); |
| } |
| |
| catch (ArgumentException e) |
| { |
| AddFileOpenErrorRecord(e); |
| throw; |
| } |
| catch (IOException e) |
| { |
| if (NoClobber && File.Exists(resolvedPath)) |
| { |
| string msg = StringUtil.Format( |
| PathUtilsStrings.UtilityFileExistsNoClobber, |
| filePath, |
| "NoClobber"); |
|
|
| |
| ErrorRecord errorRecord = new ErrorRecord( |
| e, "NoClobber", ErrorCategory.ResourceExists, resolvedPath); |
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
|
|
| e.Data[typeof(ErrorRecord)] = errorRecord; |
| throw; |
| } |
|
|
| AddFileOpenErrorRecord(e); |
| throw; |
| } |
| catch (UnauthorizedAccessException e) |
| { |
| AddFileOpenErrorRecord(e); |
| throw; |
| } |
| catch (NotSupportedException e) |
| { |
| AddFileOpenErrorRecord(e); |
| throw; |
| } |
| catch (System.Security.SecurityException e) |
| { |
| AddFileOpenErrorRecord(e); |
| throw; |
| } |
|
|
| static void AddFileOpenErrorRecord(Exception e) |
| { |
| ErrorRecord errorRecord = new ErrorRecord( |
| e, |
| "FileOpenFailure", |
| ErrorCategory.OpenError, |
| null); |
|
|
| e.Data[typeof(ErrorRecord)] = errorRecord; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| internal static void MasterStreamOpenImpl( |
| string resolvedPath, |
| Encoding resolvedEncoding, |
| bool defaultEncoding, |
| bool Append, |
| bool Force, |
| bool NoClobber, |
| out FileStream fileStream, |
| out StreamWriter streamWriter, |
| out FileInfo readOnlyFileInfo) |
| { |
| fileStream = null; |
| streamWriter = null; |
| readOnlyFileInfo = null; |
|
|
| |
| |
| FileMode mode = FileMode.Create; |
| if (Append) |
| { |
| mode = FileMode.Append; |
| } |
| else if (NoClobber) |
| { |
| |
| mode = FileMode.CreateNew; |
| } |
|
|
| if (Force && (Append || !NoClobber)) |
| { |
| if (File.Exists(resolvedPath)) |
| { |
| FileInfo fInfo = new FileInfo(resolvedPath); |
| if ((fInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) |
| { |
| |
| readOnlyFileInfo = fInfo; |
| |
| fInfo.Attributes &= ~(FileAttributes.ReadOnly); |
| } |
| } |
| } |
|
|
| |
| |
| FileShare fileShare = Force ? FileShare.ReadWrite : FileShare.Read; |
|
|
| |
| fileStream = new FileStream(resolvedPath, mode, FileAccess.Write, fileShare); |
|
|
| |
| |
| |
| |
| if (defaultEncoding) |
| streamWriter = new StreamWriter(fileStream); |
| else |
| streamWriter = new StreamWriter(fileStream, resolvedEncoding); |
| } |
|
|
| internal static void ReportFileOpenFailure(Cmdlet cmdlet, string filePath, Exception e) |
| { |
| ErrorRecord errorRecord = new ErrorRecord( |
| e, |
| "FileOpenFailure", |
| ErrorCategory.OpenError, |
| null); |
|
|
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
|
|
| internal static void ReportFileOpenFailure(string filePath, Exception e) |
| { |
| ErrorRecord errorRecord = new ErrorRecord( |
| e, |
| "FileOpenFailure", |
| ErrorCategory.OpenError, |
| null); |
|
|
| throw new RuntimeException( |
| e.Message, |
| errorRecord.Exception, |
| errorRecord); |
| } |
|
|
| internal static StreamReader OpenStreamReader(PSCmdlet command, string filePath, Encoding encoding, bool isLiteralPath) |
| { |
| FileStream fileStream = OpenFileStream(filePath, command, isLiteralPath); |
| return new StreamReader(fileStream, encoding); |
| } |
|
|
| internal static FileStream OpenFileStream(string filePath, PSCmdlet command, bool isLiteralPath) |
| { |
| string resolvedPath = PathUtils.ResolveFilePath(filePath, command, isLiteralPath); |
|
|
| try |
| { |
| return new FileStream(resolvedPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); |
| } |
| |
| catch (ArgumentException e) |
| { |
| PathUtils.ReportFileOpenFailure(command, filePath, e); |
| return null; |
| } |
| catch (IOException e) |
| { |
| PathUtils.ReportFileOpenFailure(command, filePath, e); |
| return null; |
| } |
| catch (UnauthorizedAccessException e) |
| { |
| PathUtils.ReportFileOpenFailure(command, filePath, e); |
| return null; |
| } |
| catch (NotSupportedException e) |
| { |
| PathUtils.ReportFileOpenFailure(command, filePath, e); |
| return null; |
| } |
| catch (System.Management.Automation.DriveNotFoundException e) |
| { |
| PathUtils.ReportFileOpenFailure(command, filePath, e); |
| return null; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| internal static string ResolveFilePath(string filePath, PSCmdlet command) |
| { |
| return ResolveFilePath(filePath, command, false); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| internal static string ResolveFilePath(string filePath, PSCmdlet command, bool isLiteralPath) |
| { |
| string path = null; |
|
|
| try |
| { |
| ProviderInfo provider = null; |
| PSDriveInfo drive = null; |
| List<string> filePaths = new List<string>(); |
|
|
| if (isLiteralPath) |
| { |
| filePaths.Add(command.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, out provider, out drive)); |
| } |
| else |
| { |
| filePaths.AddRange(command.SessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out provider)); |
| } |
|
|
| if (!provider.NameEquals(command.Context.ProviderNames.FileSystem)) |
| { |
| ReportWrongProviderType(command, provider.FullName); |
| } |
|
|
| if (filePaths.Count > 1) |
| { |
| ReportMultipleFilesNotSupported(command); |
| } |
|
|
| if (filePaths.Count == 0) |
| { |
| ReportWildcardingFailure(command, filePath); |
| } |
|
|
| path = filePaths[0]; |
| } |
| catch (ItemNotFoundException) |
| { |
| path = null; |
| } |
|
|
| if (string.IsNullOrEmpty(path)) |
| { |
| CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(command); |
| ProviderInfo provider = null; |
| PSDriveInfo drive = null; |
| path = |
| command.SessionState.Path.GetUnresolvedProviderPathFromPSPath( |
| filePath, cmdletProviderContext, out provider, out drive); |
| cmdletProviderContext.ThrowFirstErrorOrDoNothing(); |
| if (!provider.NameEquals(command.Context.ProviderNames.FileSystem)) |
| { |
| ReportWrongProviderType(command, provider.FullName); |
| } |
| } |
|
|
| return path; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| internal static string ResolveFilePath(string filePath, bool isLiteralPath) |
| { |
| string path = null; |
|
|
| SessionState sessionState = LocalPipeline.GetExecutionContextFromTLS()?.EngineSessionState?.PublicSessionState; |
| if (sessionState is null) |
| { |
| return null; |
| } |
|
|
| try |
| { |
| ProviderInfo provider = null; |
| PSDriveInfo drive = null; |
| List<string> filePaths = new(); |
|
|
| if (isLiteralPath) |
| { |
| filePaths.Add(sessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, out provider, out drive)); |
| } |
| else |
| { |
| filePaths.AddRange(sessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out provider)); |
| } |
|
|
| if (!provider.NameEquals(FileSystemProvider.ProviderName)) |
| { |
| ReportWrongProviderType(provider.FullName); |
| } |
|
|
| if (filePaths.Count > 1) |
| { |
| ReportMultipleFilesNotSupported(); |
| } |
|
|
| if (filePaths.Count == 0) |
| { |
| ReportWildcardingFailure(filePath); |
| } |
|
|
| path = filePaths[0]; |
| } |
| catch (ItemNotFoundException) |
| { |
| path = null; |
| } |
|
|
| return path; |
| } |
|
|
| internal static void ReportWrongProviderType(Cmdlet cmdlet, string providerId) |
| { |
| string msg = StringUtil.Format(PathUtilsStrings.OutFile_ReadWriteFileNotFileSystemProvider, providerId); |
|
|
| ErrorRecord errorRecord = new ErrorRecord( |
| PSTraceSource.NewInvalidOperationException(), |
| "ReadWriteFileNotFileSystemProvider", |
| ErrorCategory.InvalidArgument, |
| null); |
|
|
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
|
|
| internal static void ReportWrongProviderType(string providerId) |
| { |
| string msg = StringUtil.Format(PathUtilsStrings.OutFile_ReadWriteFileNotFileSystemProvider, providerId); |
|
|
| PSInvalidOperationException exception = PSTraceSource.NewInvalidOperationException(); |
|
|
| ErrorRecord errorRecord = new( |
| exception, |
| "ReadWriteFileNotFileSystemProvider", |
| ErrorCategory.InvalidArgument, |
| null); |
|
|
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
| exception.Data[typeof(ErrorRecord)] = errorRecord; |
| throw exception; |
| } |
|
|
| internal static void ReportMultipleFilesNotSupported(Cmdlet cmdlet) |
| { |
| string msg = StringUtil.Format(PathUtilsStrings.OutFile_MultipleFilesNotSupported); |
|
|
| ErrorRecord errorRecord = new ErrorRecord( |
| PSTraceSource.NewInvalidOperationException(), |
| "ReadWriteMultipleFilesNotSupported", |
| ErrorCategory.InvalidArgument, |
| null); |
|
|
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
|
|
| internal static void ReportMultipleFilesNotSupported() |
| { |
| string msg = StringUtil.Format(PathUtilsStrings.OutFile_MultipleFilesNotSupported); |
|
|
| PSInvalidOperationException exception = PSTraceSource.NewInvalidOperationException(); |
|
|
| ErrorRecord errorRecord = new( |
| exception, |
| "ReadWriteMultipleFilesNotSupported", |
| ErrorCategory.InvalidArgument, |
| null); |
|
|
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
| exception.Data[typeof(ErrorRecord)] = errorRecord; |
| throw exception; |
| } |
|
|
| internal static void ReportWildcardingFailure(Cmdlet cmdlet, string filePath) |
| { |
| string msg = StringUtil.Format(PathUtilsStrings.OutFile_DidNotResolveFile, filePath); |
|
|
| ErrorRecord errorRecord = new ErrorRecord( |
| new FileNotFoundException(), |
| "FileOpenFailure", |
| ErrorCategory.OpenError, |
| filePath); |
|
|
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
|
|
| internal static void ReportWildcardingFailure(string filePath) |
| { |
| string msg = StringUtil.Format(PathUtilsStrings.OutFile_DidNotResolveFile, filePath); |
|
|
| FileNotFoundException exception = new(); |
| ErrorRecord errorRecord = new( |
| exception, |
| "FileOpenFailure", |
| ErrorCategory.OpenError, |
| filePath); |
|
|
| errorRecord.ErrorDetails = new ErrorDetails(msg); |
| exception.Data[typeof(ErrorRecord)] = errorRecord; |
| throw exception; |
| } |
|
|
| internal static DirectoryInfo CreateModuleDirectory(PSCmdlet cmdlet, string moduleNameOrPath, bool force) |
| { |
| Dbg.Assert(cmdlet != null, "Caller should verify cmdlet != null"); |
| Dbg.Assert(!string.IsNullOrEmpty(moduleNameOrPath), "Caller should verify !string.IsNullOrEmpty(moduleNameOrPath)"); |
|
|
| DirectoryInfo directoryInfo = null; |
| try |
| { |
| |
| |
| string rootedPath = ModuleCmdletBase.ResolveRootedFilePath(moduleNameOrPath, cmdlet.Context); |
| if (string.IsNullOrEmpty(rootedPath) && moduleNameOrPath.StartsWith('.')) |
| { |
| PathInfo currentPath = cmdlet.CurrentProviderLocation(cmdlet.Context.ProviderNames.FileSystem); |
| rootedPath = Path.Combine(currentPath.ProviderPath, moduleNameOrPath); |
| } |
|
|
| if (string.IsNullOrEmpty(rootedPath)) |
| { |
| if (Path.IsPathRooted(moduleNameOrPath)) |
| { |
| rootedPath = moduleNameOrPath; |
| } |
| else |
| { |
| string personalModuleRoot = ModuleIntrinsics.GetPersonalModulePath(); |
| if (string.IsNullOrEmpty(personalModuleRoot)) |
| { |
| cmdlet.ThrowTerminatingError( |
| new ErrorRecord( |
| new ArgumentException(StringUtil.Format(PathUtilsStrings.ExportPSSession_ErrorModuleNameOrPath, moduleNameOrPath)), |
| "ExportPSSession_ErrorModuleNameOrPath", |
| ErrorCategory.InvalidArgument, |
| cmdlet)); |
| } |
|
|
| rootedPath = Path.Combine(personalModuleRoot, moduleNameOrPath); |
| } |
| } |
|
|
| directoryInfo = new DirectoryInfo(rootedPath); |
| if (directoryInfo.Exists) |
| { |
| if (!force) |
| { |
| string errorMessage = string.Format( |
| CultureInfo.InvariantCulture, |
| PathUtilsStrings.ExportPSSession_ErrorDirectoryExists, |
| directoryInfo.FullName); |
| ErrorDetails details = new ErrorDetails(errorMessage); |
| ErrorRecord errorRecord = new ErrorRecord( |
| new ArgumentException(details.Message), |
| "ExportProxyCommand_OutputDirectoryExists", |
| ErrorCategory.ResourceExists, |
| directoryInfo); |
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
| } |
| else |
| { |
| directoryInfo.Create(); |
| } |
| } |
| catch (Exception e) |
| { |
| string errorMessage = string.Format( |
| CultureInfo.InvariantCulture, |
| PathUtilsStrings.ExportPSSession_CannotCreateOutputDirectory, |
| moduleNameOrPath, |
| e.Message); |
| ErrorDetails details = new ErrorDetails(errorMessage); |
| ErrorRecord errorRecord = new ErrorRecord( |
| new ArgumentException(details.Message, e), |
| "ExportProxyCommand_CannotCreateOutputDirectory", |
| ErrorCategory.ResourceExists, |
| moduleNameOrPath); |
| cmdlet.ThrowTerminatingError(errorRecord); |
| } |
|
|
| return directoryInfo; |
| } |
|
|
| internal static DirectoryInfo CreateTemporaryDirectory() |
| { |
| DirectoryInfo temporaryDirectory = new DirectoryInfo(Path.GetTempPath()); |
| DirectoryInfo moduleDirectory; |
| do |
| { |
| moduleDirectory = new DirectoryInfo( |
| Path.Combine( |
| temporaryDirectory.FullName, |
| string.Format( |
| null, |
| "tmp_{0}", |
| Path.GetRandomFileName()))); |
| } while (moduleDirectory.Exists); |
|
|
| Directory.CreateDirectory(moduleDirectory.FullName); |
| return new DirectoryInfo(moduleDirectory.FullName); |
| } |
|
|
| internal static bool TryDeleteFile(string filepath) |
| { |
| if (IO.File.Exists(filepath)) |
| { |
| try |
| { |
| IO.File.Delete(filepath); |
| return true; |
| } |
| catch (IOException) |
| { |
| |
| } |
| catch (UnauthorizedAccessException) |
| { |
| |
| } |
| } |
|
|
| return false; |
| } |
|
|
| #region Helpers for long paths from .Net Runtime |
|
|
| |
| |
| |
|
|
| #nullable enable |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| [return: NotNullIfNotNull(nameof(path))] |
| internal static string? EnsureExtendedPrefixIfNeeded(string? path) |
| { |
| if (path != null && (path.Length >= MaxShortPath || EndsWithPeriodOrSpace(path))) |
| { |
| return EnsureExtendedPrefix(path); |
| } |
| else |
| { |
| return path; |
| } |
| } |
|
|
| internal static string EnsureExtendedPrefix(string path) |
| { |
| if (IsPartiallyQualified(path) || IsDevice(path)) |
| return path; |
|
|
| |
| if (path.StartsWith(UncPathPrefix, StringComparison.OrdinalIgnoreCase)) |
| return path.Insert(2, UncDevicePrefixToInsert); |
|
|
| return ExtendedDevicePathPrefix + path; |
| } |
|
|
| private const string ExtendedDevicePathPrefix = @"\\?\"; |
| private const string UncPathPrefix = @"\\"; |
| private const string UncDevicePrefixToInsert = @"?\UNC\"; |
| private const string UncExtendedPathPrefix = @"\\?\UNC\"; |
| private const string DevicePathPrefix = @"\\.\"; |
| private const int MaxShortPath = 260; |
|
|
| |
| private const int DevicePrefixLength = 4; |
|
|
| private static bool EndsWithPeriodOrSpace(string? path) |
| { |
| if (string.IsNullOrEmpty(path)) |
| { |
| return false; |
| } |
|
|
| char c = path[path.Length - 1]; |
| return c == ' ' || c == '.'; |
| } |
|
|
| |
| |
| |
| private static bool IsValidDriveChar(char value) |
| { |
| return ((value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z')); |
| } |
|
|
| private static bool IsDevice(string path) |
| { |
| return IsExtended(path) |
| || |
| ( |
| path.Length >= DevicePrefixLength |
| && IsDirectorySeparator(path[0]) |
| && IsDirectorySeparator(path[1]) |
| && (path[2] == '.' || path[2] == '?') |
| && IsDirectorySeparator(path[3]) |
| ); |
| } |
|
|
| private static bool IsExtended(string path) |
| { |
| return path.Length >= DevicePrefixLength |
| && path[0] == '\\' |
| && (path[1] == '\\' || path[1] == '?') |
| && path[2] == '?' |
| && path[3] == '\\'; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private static bool IsPartiallyQualified(string path) |
| { |
| if (path.Length < 2) |
| { |
| |
| |
| return true; |
| } |
|
|
| if (IsDirectorySeparator(path[0])) |
| { |
| |
| |
| return !(path[1] == '?' || IsDirectorySeparator(path[1])); |
| } |
|
|
| |
| |
| return !((path.Length >= 3) |
| && (path[1] == Path.VolumeSeparatorChar) |
| && IsDirectorySeparator(path[2]) |
| |
| |
| && IsValidDriveChar(path[0])); |
| } |
| |
| |
| |
| [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| private static bool IsDirectorySeparator(char c) |
| { |
| return c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar; |
| } |
|
|
| #endregion |
|
|
| #region Helpers for checking invalid paths using SearchValues |
|
|
| |
| |
| |
| private static readonly SearchValues<char> s_invalidFileNameChars |
| = SearchValues.Create(Path.GetInvalidFileNameChars()); |
|
|
| |
| |
| |
| private static readonly SearchValues<char> s_invalidPathChars |
| = SearchValues.Create(Path.GetInvalidPathChars()); |
|
|
| |
| |
| |
| |
| |
| internal static bool ContainsInvalidFileNameChars(ReadOnlySpan<char> filename) |
| => filename.ContainsAny(s_invalidFileNameChars); |
|
|
| |
| |
| |
| |
| |
| internal static bool ContainsInvalidPathChars(ReadOnlySpan<char> path) |
| => path.ContainsAny(s_invalidPathChars); |
|
|
| #endregion |
| } |
| } |
|
|