Skip to content

Commit

Permalink
Normalize path separators in-place
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Jul 9, 2024
1 parent 9f9a0d5 commit 9488692
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions Bonsai.Configuration/PackageConfigurationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PackageConfigurationUpdater : IDisposable
public PackageConfigurationUpdater(NuGetFramework projectFramework, PackageConfiguration configuration, IPackageManager manager, string bootstrapperPath = null, PackageIdentity bootstrapperName = null)
{
packageManager = manager ?? throw new ArgumentNullException(nameof(manager));
packageConfiguration = NormalizePathSeparators(configuration ?? throw new ArgumentNullException(nameof(configuration)));
packageConfiguration = configuration ?? throw new ArgumentNullException(nameof(configuration));
bootstrapperFramework = projectFramework ?? throw new ArgumentNullException(nameof(projectFramework));
bootstrapperExePath = bootstrapperPath ?? string.Empty;
bootstrapperDirectory = Path.GetDirectoryName(bootstrapperExePath);
Expand All @@ -58,6 +58,7 @@ public PackageConfigurationUpdater(NuGetFramework projectFramework, PackageConfi
var galleryPath = Path.Combine(bootstrapperDirectory, GalleryDirectory);
var galleryPackageSource = new PackageSource(galleryPath);
galleryRepository = new SourceRepository(galleryPackageSource, Repository.Provider.GetCoreV3());
NormalizePathSeparators(packageConfiguration);
}

string GetRelativePath(string path)
Expand All @@ -74,29 +75,21 @@ static string CombinePath(string path1, string path2)
return PathUtility.GetPathWithForwardSlashes(Path.Combine(path1, path2));
}

static PackageConfiguration NormalizePathSeparators(PackageConfiguration configuration)
static void NormalizePathSeparators(PackageConfiguration configuration)
{
var normalized = new PackageConfiguration();
normalized.ConfigurationFile = configuration.ConfigurationFile;
normalized.Packages.AddRange(configuration.Packages);
normalized.AssemblyReferences.AddRange(configuration.AssemblyReferences);

foreach (var assemblyLocation in configuration.AssemblyLocations)
{
normalized.AssemblyLocations.Add(
assemblyLocation.AssemblyName,
assemblyLocation.ProcessorArchitecture,
PathUtility.GetPathWithForwardSlashes(assemblyLocation.Location));
assemblyLocation.Location = PathUtility.GetPathWithForwardSlashes(assemblyLocation.Location);
}

foreach (var folder in configuration.LibraryFolders)
// cannot normalize in place since path is collection key
var libraryFolders = configuration.LibraryFolders.ToArray();
configuration.LibraryFolders.Clear();
foreach (var folder in libraryFolders)
{
normalized.LibraryFolders.Add(
PathUtility.GetPathWithForwardSlashes(folder.Path),
folder.Platform);
folder.Path = PathUtility.GetPathWithForwardSlashes(folder.Path);
configuration.LibraryFolders.Add(folder);
}

return normalized;
}

static bool IsTaggedPackage(PackageReaderBase package)
Expand Down

0 comments on commit 9488692

Please sign in to comment.