Skip to content

Commit 1ca42bb

Browse files
committed
[Xamarin.Android.Build.Tasks] Fix issues with Library Resource Extraction
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).
1 parent 474dc74 commit 1ca42bb

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ void Extract (
232232

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

237238
// We used to *copy* the resources to overwrite other resources,
238239
// which resulted in missing resource issue.

src/Xamarin.Android.Build.Tasks/Utilities/Files.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,17 @@ public static void ExtractAll(ZipArchive zip, string destination, Action<int, in
198198
int i = 0;
199199
int total = zip.Entries.Count;
200200
foreach (var entry in zip.Entries) {
201-
202-
if (string.Equals(entry.FullName, "__MACOSX", StringComparison.OrdinalIgnoreCase) ||
203-
string.Equals(entry.FullName, ".DS_Store", StringComparison.OrdinalIgnoreCase))
201+
if (entry.FullName.Contains ("/__MACOSX/") ||
202+
entry.FullName.EndsWith ("/__MACOSX", StringComparison.OrdinalIgnoreCase) ||
203+
entry.FullName.EndsWith ("/.DS_Store", StringComparison.OrdinalIgnoreCase))
204204
continue;
205205
if (entry.IsDirectory ()) {
206206
Directory.CreateDirectory (Path.Combine (destination, entry.FullName));
207207
continue;
208208
}
209209
if (progressCallback != null)
210210
progressCallback (i++, total);
211+
Directory.CreateDirectory (Path.Combine (destination, Path.GetDirectoryName (entry.FullName)));
211212
entry.ExtractToFile (Path.Combine (destination, entry.FullName), overwrite: true);
212213
}
213214
}

src/Xamarin.Android.Build.Tasks/Utilities/ZipArchiveExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static void AddFiles (this ZipArchive archive, IEnumerable<string> fileNa
7474

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

8080
public static bool IsDirectory (this ZipArchiveEntry entry)

0 commit comments

Comments
 (0)