Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Fix issues with Library Resource Extrac…
Browse files Browse the repository at this point in the history
…tion

Since the switch to System.IO.Compression we have a few
issues when dealing with resource extraction.

1) It was not ignoring _MACOSX or .DS_Store during extraction.
2) It was not correctly detecting duplicate zip entries.

This commit updates the code to correctly filter _MACOSX and
.DS_Store entries. It also changes the way we check if an entry
exists in the zip already. And finally it updates
ResolveLibraryProjectImports to use the Files.ExtractAll method.
This is because the standard ZipFile.ExtractToDirectory has no
way of filtering the output (so it includes _MACOSX and .DS_Store).
  • Loading branch information
dellis1972 committed Jun 9, 2016
1 parent 474dc74 commit 5b48c9e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ void Extract (

// temporarily extracted directory will look like:
// __library_projects__/[dllname]/[library_project_imports | jlibs]/bin
ZipFile.ExtractToDirectory (finfo.FullName, outDirForDll);
using (var zip = MonoAndroidHelper.ReadZipFile (finfo.FullName))
Files.ExtractAll (zip, outDirForDll);

// We used to *copy* the resources to overwrite other resources,
// which resulted in missing resource issue.
Expand Down
6 changes: 3 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Utilities/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ public static void ExtractAll(ZipArchive zip, string destination, Action<int, in
int i = 0;
int total = zip.Entries.Count;
foreach (var entry in zip.Entries) {

if (string.Equals(entry.FullName, "__MACOSX", StringComparison.OrdinalIgnoreCase) ||
string.Equals(entry.FullName, ".DS_Store", StringComparison.OrdinalIgnoreCase))
if (entry.FullName.Contains ("__MACOSX") ||
entry.FullName.EndsWith (".DS_Store", StringComparison.OrdinalIgnoreCase))
continue;
if (entry.IsDirectory ()) {
Directory.CreateDirectory (Path.Combine (destination, entry.FullName));
continue;
}
if (progressCallback != null)
progressCallback (i++, total);
Directory.CreateDirectory (Path.Combine (destination, Path.GetDirectoryName (entry.FullName)));
entry.ExtractToFile (Path.Combine (destination, entry.FullName), overwrite: true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void AddFiles (this ZipArchive archive, IEnumerable<string> fileNa

public static bool ContainsEntry (this ZipArchive archive, string entryName)
{
return archive.Entries.Any (x => string.Compare (x.Name, entryName, StringComparison.OrdinalIgnoreCase) == 0);
return archive.Entries.Any (x => string.Compare (x.FullName, entryName, StringComparison.OrdinalIgnoreCase) == 0);
}

public static bool IsDirectory (this ZipArchiveEntry entry)
Expand Down

0 comments on commit 5b48c9e

Please sign in to comment.