Skip to content

Commit 423ae68

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Fix a bug when extracting resources. (#847)
There is a small bug in the zip extraction. We were using `FileMode.OpenOrCreate` to write the files. The problem is `OpenOrCreate` does not truncate the file if it exists. So if we have a resource which is smaller than the file on disk we end up with additonal stuff at the end of it.. So lets use `Create` instead which will truncate the file if it exists aleady.
1 parent 87e6433 commit 423ae68

File tree

1 file changed

+1
-1
lines changed
  • src/Xamarin.Android.Build.Tasks/Utilities

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static bool ExtractAll(ZipArchive zip, string destination, Action<int, in
226226
var dt = File.Exists (outfile) ? File.GetLastWriteTimeUtc (outfile) : DateTime.MinValue;
227227
if (forceUpdate || entry.ModificationTime > dt) {
228228
try {
229-
entry.Extract (destination, fullName, FileMode.OpenOrCreate);
229+
entry.Extract (destination, fullName, FileMode.Create);
230230
} catch (PathTooLongException) {
231231
throw new PathTooLongException ($"Could not extract \"{fullName}\" to \"{outfile}\". Path is too long.");
232232
}

0 commit comments

Comments
 (0)