Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix duplicate content #657

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions src/NuGetForUnity/Editor/NugetPackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets,
// unzip the package
using (var zip = ZipFile.OpenRead(cachedPackagePath))
{
// check if nuget package has contentFiles folder
const string contentFilesDirectoryName = "contentFiles/";
var hasContentFilesFolder = false;
foreach (var entry in zip.Entries)
{
if (entry.FullName.EndsWith("/") && entry.FullName.Equals(contentFilesDirectoryName, StringComparison.OrdinalIgnoreCase))
{
hasContentFilesFolder = true;
break;
}
}

var libs = new Dictionary<string, List<ZipArchiveEntry>>();
var csFiles = new Dictionary<string, List<ZipArchiveEntry>>();
var anyFiles = new Dictionary<string, List<ZipArchiveEntry>>();
Expand All @@ -179,7 +191,7 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets,
continue;
}

if (PackageContentManager.ShouldSkipUnpackingOnPath(entryFullName))
if (PackageContentManager.ShouldSkipUnpackingOnPath(entryFullName, hasContentFilesFolder))
{
continue;
}
Expand All @@ -206,7 +218,6 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets,

// in case this is a source code package, we want to collect all its entries that have 'cs' or 'any' set as language
// and their frameworks so we can get the best framework later
const string contentFilesDirectoryName = "contentFiles/";
if (entryFullName.StartsWith(contentFilesDirectoryName, StringComparison.Ordinal))
{
// Folder structure for source code packages:
Expand Down
12 changes: 11 additions & 1 deletion src/NuGetForUnity/Editor/PackageContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ internal static void CleanInstallationDirectory([NotNull] INugetPackageIdentifie
/// The path of the file inside the .nupkg it is relative starting from the package route. It always uses '/' as a slash on all
/// platforms.
/// </param>
/// <param name="hasContentFilesFolder">
/// The package has contentfiles folder, we need to omit content folder it exist. Because some nuget package has both folder to
/// to support old version and new version of nuget.
/// </param>
/// <returns>True if the file can be skipped, is not needed.</returns>
internal static bool ShouldSkipUnpackingOnPath([NotNull] string path)
internal static bool ShouldSkipUnpackingOnPath([NotNull] string path, bool hasContentFilesFolder)
{
if (path.EndsWith("/"))
{
Expand All @@ -120,6 +124,12 @@ internal static bool ShouldSkipUnpackingOnPath([NotNull] string path)
return true;
}

// skip content folder when it has contentFiles folder
if (hasContentFilesFolder && (path.StartsWith("content/", StringComparison.Ordinal) || path.Contains("/content/")))
{
return true;
}

// skip directories & files that NuGet normally deletes
if (path.StartsWith("_rels/", StringComparison.Ordinal) || path.Contains("/_rels/"))
{
Expand Down
Loading