Skip to content

Commit

Permalink
Fix regression with rooted paths without volume labels on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Metapyziks committed Jul 25, 2024
1 parent a7e549f commit f63488d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Zio/FileSystems/PhysicalFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,11 @@ protected override string ConvertPathToInternalImpl(UPath path)
return absolutePath;
}

private static bool HasWindowsVolumeLabel(string path)
{
return path.IndexOf(":\\", StringComparison.Ordinal) == 1;
}

/// <inheritdoc />
protected override UPath ConvertPathFromInternalImpl(string innerPath)
{
Expand All @@ -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();
Expand Down

0 comments on commit f63488d

Please sign in to comment.