Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ private SortedSet<string> WriteFiles(ZipArchive package, SortedSet<string> files
var warningMessage = new StringBuilder();

// Add files that might not come from expanding files on disk
foreach (IPackageFile file in new HashSet<IPackageFile>(Files))
foreach (IPackageFile file in new SortedSet<IPackageFile>(Files, new DirectorySeparatorAmbivalentComparer()))
{
using (Stream stream = file.GetStream())
{
Expand Down Expand Up @@ -1378,5 +1378,15 @@ private string GenerateRelationshipId(string path)
return "R" + hex.Substring(0, 16);
}
}

private class DirectorySeparatorAmbivalentComparer : IComparer<IPackageFile>
Comment thread
omajid marked this conversation as resolved.
Outdated
{
public int Compare(IPackageFile x, IPackageFile y)
{
string xPathNormalized = x.Path.Replace('\\', '/');
string yPathNormalized = y.Path.Replace('\\', '/');
return String.CompareOrdinal(xPathNormalized, yPathNormalized);
Comment thread
zivkan marked this conversation as resolved.
}
}
}
}
45 changes: 19 additions & 26 deletions test/NuGet.Core.Tests/NuGet.Packaging.Test/PackageBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public void CreatePackageWithEmptyFoldersForV3Folders()
var files = archive.Entries
.Where(file => file.Name == "_._")
.Select(file => file.FullName)
.OrderBy(s => s)
Comment thread
omajid marked this conversation as resolved.
.ToArray();

// Assert
Expand Down Expand Up @@ -150,7 +149,6 @@ public void CreatePackageWithDifferentFileKinds()
var files = archive.Entries
.Where(file => file.Name.StartsWith("foo"))
.Select(file => file.FullName)
.OrderBy(s => s)
.ToArray();

// Assert
Expand Down Expand Up @@ -2776,21 +2774,20 @@ public void PackageBuilderWorksWithFileNamesContainingSpecialCharacters()
using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true))
{
// Get raw filenames without un-escaping.
var files = archive.Entries.Select(e => e.FullName).OrderBy(s => s).ToArray();
var files = archive.Entries.Select(e => e.FullName).ToArray();

// Linux sorts the first two in different order than Windows
Assert.Contains<string>(@"[Content_Types].xml", files);
Assert.Contains<string>(@"_rels/.rels", files);
Assert.Equal(@"_rels/.rels", files[0]);
Assert.Equal(@"test.nuspec", files[1]);
Assert.Equal(@"content/images/bread&butter.jpg", files[2]);
Assert.Equal(@"content/images/logo123?#78.png", files[3]);
Assert.Equal(@"lib/C#/test.dll", files[4]);
Assert.Equal(@"lib/name with spaces.dll", files[5]);
Assert.Equal(@"lib/regular.file.dll", files[6]);

Assert.StartsWith(@"package/services/metadata/core-properties/", files[7]);
Assert.EndsWith(@".psmdcp", files[7]);
Assert.Equal(@"[Content_Types].xml", files[7]);
Assert.StartsWith(@"package/services/metadata/core-properties/", files[8]);
Assert.EndsWith(@".psmdcp", files[8]);

Assert.Equal(@"test.nuspec", files[8]);
}
}
}
Expand Down Expand Up @@ -2818,17 +2815,14 @@ public void PackageBuilderWorksWithFileNameWithoutAnExtension()

using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true))
{
var files = archive.GetFiles().OrderBy(s => s).ToArray();
var files = archive.GetFiles().ToArray();

// Linux sorts the first two in different order than Windows
Assert.Contains<string>(@"[Content_Types].xml", files);
Assert.Contains<string>(@"_rels/.rels", files);
Assert.Equal(@"_rels/.rels", files[0]);
Assert.Equal(@"test.nuspec", files[1]);
Assert.Equal(@"myfile", files[2]);

Assert.StartsWith(@"package/services/metadata/core-properties/", files[3]);
Assert.EndsWith(@".psmdcp", files[3]);

Assert.Equal(@"test.nuspec", files[4]);
Assert.Equal(@"[Content_Types].xml", files[3]);
Assert.StartsWith(@"package/services/metadata/core-properties/", files[4]);
Assert.EndsWith(@".psmdcp", files[4]);

using (var contentTypesReader = new StreamReader(archive.Entries.Single(file => file.FullName == @"[Content_Types].xml").Open()))
{
Expand Down Expand Up @@ -3028,14 +3022,13 @@ public void PackageBuilderWorksWithFilesHavingCurrentDirectoryAsTarget(string in

using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true))
{
var files = archive.GetFiles().OrderBy(s => s).ToArray();

// Linux sorts the first two in different order than Windows
Assert.Contains<string>(@"[Content_Types].xml", files);
Assert.Contains<string>(@"_rels/.rels", files);
Assert.StartsWith(@"package/services/metadata/core-properties/", files[2]);
Assert.Equal(@"test.nuspec", files[3]);
Assert.Equal(outputFile, files[4]);
var files = archive.GetFiles().ToArray();

Assert.Equal(@"_rels/.rels", files[0]);
Assert.Equal(@"test.nuspec", files[1]);
Assert.Equal(outputFile, files[2]);
Assert.Equal(@"[Content_Types].xml", files[3]);
Assert.StartsWith(@"package/services/metadata/core-properties/", files[4]);
}
}
}
Expand Down