Skip to content

Commit 664f8a6

Browse files
authored
Fix regression that broke UNC path handling (#17902)
With `IOUri`, I had intentionally dropped UNC path support, assuming that it wouldn't to be needed because it's Windows specific. However, this support turns out to be essential when invoking the Windows version of Bicep from WSL, since resolved file paths are UNC paths (e.g., \\wsl.localhost\Ubuntu-22.04\home\main.bicep). This PR restores UNC path support for `IOUri`. Closes #17843. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/17902)
1 parent 034413c commit 664f8a6

File tree

25 files changed

+208
-87
lines changed

25 files changed

+208
-87
lines changed

src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public async Task Build_Valid_SingleFile_WithTemplateSpecReference_ShouldSucceed
8383
// ensure something got restored
8484

8585
settings.FeatureOverrides!.CacheRootDirectory!.Exists().Should().BeTrue();
86-
Directory.EnumerateFiles(settings.FeatureOverrides.CacheRootDirectory!.Uri.GetLocalFilePath(), "*.json", SearchOption.AllDirectories).Should().NotBeEmpty();
86+
Directory.EnumerateFiles(settings.FeatureOverrides.CacheRootDirectory!.Uri.GetFilePath(), "*.json", SearchOption.AllDirectories).Should().NotBeEmpty();
8787
}
8888

8989
var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);

src/Bicep.Cli.IntegrationTests/RestoreCommandTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ await RegistryHelper.PublishModuleToRegistryAsync(
122122
fileSystem.Directory.SetCurrentDirectory(outputPath);
123123
}
124124

125-
var cacheRoot = fileExplorer.GetDirectory(IOUri.FromLocalFilePath(outputPath));
125+
var cacheRoot = fileExplorer.GetDirectory(IOUri.FromFilePath(outputPath));
126126

127127
var (output, error, result) = await Bicep(
128128
services => services
@@ -260,7 +260,7 @@ public async Task Restore_Artifacts_BackwardsAndForwardsCompatibility(string? me
260260
var restoredFile = cacheRootDirectory.GetFile("restored.bicep");
261261
restoredFile.Write(bicep);
262262

263-
var restoredFilePath = restoredFile.Uri.GetLocalFilePath();
263+
var restoredFilePath = restoredFile.Uri.GetFilePath();
264264
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);
265265

266266
var (output, error, result) = await Bicep(settings, "restore", restoredFilePath);
@@ -340,7 +340,7 @@ public async Task Restore_Artifacts_LayerMediaTypes(string[] layerMediaTypes, st
340340
var restoredFile = cacheRootDirectory.GetFile("restored.bicep");
341341
restoredFile.Write(bicep);
342342

343-
var restoredFilePath = restoredFile.Uri.GetLocalFilePath();
343+
var restoredFilePath = restoredFile.Uri.GetFilePath();
344344

345345
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);
346346

src/Bicep.Cli.UnitTests/Arguments/InputOutputArgumentsResolverTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void PathToUri_should_accept_backslash_paths_on_windows(string windowsPat
132132

133133
// Assert
134134
result.Should().NotBeNull();
135-
result.IsLocalFile.Should().BeTrue();
135+
result.IsFile.Should().BeTrue();
136136
mockPath.Verify(p => p.GetFullPath(windowsPath), Times.Once);
137137
}
138138
#endif
@@ -156,7 +156,7 @@ public void PathToUri_should_accept_slash_on_all_platforms(string path)
156156

157157
// Assert
158158
result.Should().NotBeNull();
159-
result.IsLocalFile.Should().BeTrue();
159+
result.IsFile.Should().BeTrue();
160160
mockPath.Verify(p => p.GetFullPath(path), Times.Once);
161161
}
162162
}

src/Bicep.Cli/Arguments/InputOutputArgumentsResolver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public IOUri PathToUri(string path)
2424
throw new CommandLineException(string.Format(CliResources.FilePathContainsBackslash, path));
2525
}
2626

27-
return IOUri.FromLocalFilePath(GetFullPath(path));
27+
return IOUri.FromFilePath(GetFullPath(path));
2828
}
2929

3030
public IOUri ResolveInputArguments(IInputArguments arguments)
@@ -84,7 +84,7 @@ public IReadOnlyList<IOUri> ResolveFilePatternInputArguments(IFilePatternInputAr
8484
foreach (var inputRelativePath in inputRelativePaths)
8585
{
8686
var inputUri = rootUri.Resolve(inputRelativePath);
87-
var outputRootPath = arguments.OutputDir ?? rootUri.GetLocalFilePath();
87+
var outputRootPath = arguments.OutputDir ?? rootUri.GetFilePath();
8888
var outputRelativePath = this.fileSystem.Path.ChangeExtension(inputRelativePath, T.OutputFileExtensionResolver.Invoke(arguments, inputUri));
8989
var outputPath = this.fileSystem.Path.Combine(outputRootPath, outputRelativePath);
9090
var outputUri = this.PathToUri(outputPath);
@@ -122,15 +122,15 @@ private IOUri ResolveOutputUri(IOUri inputUri, string? outputDir, string? output
122122
private (IOUri rootUri, IReadOnlyList<string> relativePaths) ResolveFilePattern(string filePattern)
123123
{
124124
var (rootPath, relativePattern) = SplitFilePatternOnWildcard(filePattern);
125-
var rootUri = IOUri.FromLocalFilePath(rootPath);
125+
var rootUri = IOUri.FromFilePath(rootPath);
126126

127127
Matcher matcher = new();
128128
matcher.AddInclude(relativePattern);
129129

130130
var relativePaths = new List<string>();
131131
foreach (var filePath in matcher.GetResultsInFullPath(rootPath))
132132
{
133-
var fileUri = IOUri.FromLocalFilePath(filePath);
133+
var fileUri = IOUri.FromFilePath(filePath);
134134
var relativePath = fileUri.GetPathRelativeTo(rootUri);
135135
relativePaths.Add(relativePath);
136136
}

src/Bicep.Cli/Commands/PublishExtensionCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ private async Task<IFileHandle> GetTypesFromExtension(IOUri binaryUri, Cancellat
182182

183183
var fileExplorer = new InMemoryFileExplorer();
184184

185-
var indexUri = IOUri.FromLocalFilePath("/index.json");
185+
var indexUri = IOUri.FromFilePath("/index.json");
186186
var indexHandle = fileExplorer.GetFile(indexUri);
187187
indexHandle.Write(typeFiles.IndexFileContent);
188188

189189
foreach (var (path, content) in typeFiles.TypeFileContents)
190190
{
191-
var fileUri = IOUri.FromLocalFilePath($"/{path}");
191+
var fileUri = IOUri.FromFilePath($"/{path}");
192192
fileExplorer.GetFile(fileUri).Write(content);
193193
}
194194

src/Bicep.Cli/Commands/SnapshotCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private Snapshot ReadSnapshot(IOUri uri)
132132
if (!file.TryReadAllText().IsSuccess(out var contents, out var failureBuilder))
133133
{
134134
var message = failureBuilder(DiagnosticBuilder.ForDocumentStart()).Message;
135-
throw new CommandLineException($"Error opening file {uri.GetLocalFilePath()}: {message}.");
135+
throw new CommandLineException($"Error opening file {uri.GetFilePath()}: {message}.");
136136
}
137137

138138
return SnapshotHelper.Deserialize(contents);

src/Bicep.Cli/Rpc/CliJsonRpcServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Task<GetFileReferencesResponse> GetFileReferences(GetFileReferences
111111
}
112112

113113
return new(
114-
[.. fileUris.Select(x => x.GetLocalFilePath()).OrderBy(x => x)]);
114+
[.. fileUris.Select(x => x.GetFilePath()).OrderBy(x => x)]);
115115
}
116116

117117
/// <inheritdoc/>

src/Bicep.Core.UnitTests/Registry/CachedModules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class CachedModules
2222
// Get all cached modules from the local on-disk registry cache
2323
public static ImmutableArray<CachedModule> GetCachedModules(IFileSystem fileSystem, IDirectoryHandle cacheRootDirectory)
2424
{
25-
var cacheDir = fileSystem.DirectoryInfo.New(cacheRootDirectory.Uri.GetLocalFilePath());
25+
var cacheDir = fileSystem.DirectoryInfo.New(cacheRootDirectory.Uri.GetFilePath());
2626
if (!cacheDir.Exists)
2727
{
2828
return [];

src/Bicep.Core.UnitTests/Registry/OciModuleRegistryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ private OciArtifactReference CreateModuleReference(BicepSourceFile referencingFi
742742
var parentModuleUri = new Uri(bicepPath);
743743

744744
var featureProviderMock = StrictMock.Of<IFeatureProvider>();
745-
var cacheRootDirectory = BicepTestConstants.FileExplorer.GetDirectory(IOUri.FromLocalFilePath(TestOutputPath));
745+
var cacheRootDirectory = BicepTestConstants.FileExplorer.GetDirectory(IOUri.FromFilePath(TestOutputPath));
746746
featureProviderMock.Setup(m => m.CacheRootDirectory).Returns(cacheRootDirectory);
747747

748748
var featureProviderFactoryMock = StrictMock.Of<IFeatureProviderFactory>();

src/Bicep.Core.UnitTests/Utils/FileHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static string SaveEmbeddedResourcesWithPathPrefix(TestContext testContext
8383
public static IDirectoryHandle GetCacheRootDirectory(TestContext testContext)
8484
{
8585
var path = GetUniqueTestOutputPath(testContext);
86-
var uri = IOUri.FromLocalFilePath(path);
86+
var uri = IOUri.FromFilePath(path);
8787

8888
return BicepTestConstants.FileExplorer.GetDirectory(uri);
8989
}

0 commit comments

Comments
 (0)