diff --git a/src/Zio/FileSystems/PhysicalFileSystem.cs b/src/Zio/FileSystems/PhysicalFileSystem.cs index ffc659f..555bd95 100644 --- a/src/Zio/FileSystems/PhysicalFileSystem.cs +++ b/src/Zio/FileSystems/PhysicalFileSystem.cs @@ -968,6 +968,11 @@ protected override string ConvertPathToInternalImpl(UPath path) return absolutePath; } + private static bool HasWindowsVolumeLabel(string path) + { + return path.IndexOf(":\\", StringComparison.Ordinal) == 1; + } + /// protected override UPath ConvertPathFromInternalImpl(string innerPath) { @@ -977,9 +982,10 @@ protected override UPath ConvertPathFromInternalImpl(string innerPath) if (innerPath.StartsWith(@"\\", StringComparison.Ordinal) || innerPath.StartsWith(@"\?", StringComparison.Ordinal)) throw new NotSupportedException($"Path starting with `\\\\` or `\\?` are not supported -> `{innerPath}` "); - var absolutePath = Path.IsPathRooted(innerPath) ? innerPath : Path.GetFullPath(innerPath); - var driveIndex = absolutePath.IndexOf(":\\", StringComparison.Ordinal); - if (driveIndex != 1) + var absolutePath = HasWindowsVolumeLabel(innerPath) ? innerPath : Path.GetFullPath(innerPath); + + // Assert that Path.GetFullPath returned the format we expect + if (!HasWindowsVolumeLabel(absolutePath)) throw new ArgumentException($"Expecting a drive for the path `{absolutePath}`"); var builder = UPath.GetSharedStringBuilder();