|
1 | 1 | <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
2 | 2 |
|
3 | 3 |
|
4 |
| -<!-- some massive files are deliverd in fragments across multiple nuget packages --> |
| 4 | +<!-- Some massive files > 1GB are delivered in fragments across multiple nuget packages. --> |
| 5 | +<!-- Here we hack them back together on first build using the package install --> |
5 | 6 | <UsingTask
|
6 | 7 | TaskName="FileDefragger"
|
7 | 8 | TaskFactory="RoslynCodeTaskFactory"
|
|
35 | 36 |
|
36 | 37 | if (File.Exists(fragmentFile1) && File.Exists(fragmentFile2) && File.Exists(fragmentFile3))
|
37 | 38 | {
|
38 |
| - System.Console.WriteLine("Fragment files in parallel nuget packages for {0}", primaryFile); |
39 |
| -
|
40 | 39 | Console.WriteLine("Found fragment file at {0}", fragmentFile1);
|
41 | 40 | Console.WriteLine("Found fragment file at {0}", fragmentFile2);
|
42 | 41 | Console.WriteLine("Found fragment file at {0}", fragmentFile3);
|
43 | 42 | var primaryBytes = File.ReadAllBytes(primaryFile);
|
44 | 43 | var fragmentBytes1 = File.ReadAllBytes(fragmentFile1);
|
45 | 44 | var fragmentBytes2 = File.ReadAllBytes(fragmentFile2);
|
46 | 45 | var fragmentBytes3 = File.ReadAllBytes(fragmentFile3);
|
| 46 | + var outputBytes = new byte[primaryBytes.Length + fragmentBytes1.Length + fragmentBytes2.Length + fragmentBytes3.Length]; |
47 | 47 |
|
48 |
| - if (primaryBytes.Length != fragmentBytes1.Length) |
49 |
| - throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile1))); |
50 |
| -
|
51 |
| - if (primaryBytes.Length != fragmentBytes2.Length) |
52 |
| - throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile2))); |
53 |
| -
|
54 |
| - if (primaryBytes.Length != fragmentBytes3.Length) |
55 |
| - throw (new Exception(String.Format("Mismatched file sizes for multi-package deliver of single massive binary file. Primary file {0} found, but the corresponding fragment at {1} has a different size. You may have inconsistent nuget package references.", primaryFile, fragmentFile3))); |
56 |
| -
|
57 |
| - for (int i = 0; i < primaryBytes.Length; i++) |
58 |
| - { |
59 |
| - if ((primaryBytes[i] > 0) && (fragmentBytes1[i] > 0) && (primaryBytes[i] != fragmentBytes1[i])) |
60 |
| - throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile1))); |
61 |
| - if ((primaryBytes[i] > 0) && (fragmentBytes2[i] > 0) && (primaryBytes[i] != fragmentBytes2[i])) |
62 |
| - throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile2))); |
63 |
| - if ((primaryBytes[i] > 0) && (fragmentBytes3[i] > 0) && (primaryBytes[i] != fragmentBytes3[i])) |
64 |
| - throw (new Exception(String.Format("Inconsistent file contents for multi-package deliver of single massive binary file. Primary file {0} and corresponding fragment {1} had inconsistent contents. You may have inconsistent nuget package references.", primaryFile, fragmentFile3))); |
65 |
| - primaryBytes[i] |= fragmentBytes1[i]; |
66 |
| - primaryBytes[i] |= fragmentBytes2[i]; |
67 |
| - primaryBytes[i] |= fragmentBytes3[i]; |
68 |
| - } |
| 48 | + Array.Copy(primaryBytes, 0, outputBytes, 0, primaryBytes.Length); |
| 49 | + Array.Copy(fragmentBytes1, 0, outputBytes, primaryBytes.Length, fragmentBytes1.Length); |
| 50 | + Array.Copy(fragmentBytes2, 0, outputBytes, primaryBytes.Length + fragmentBytes1.Length, fragmentBytes2.Length); |
| 51 | + Array.Copy(fragmentBytes3, 0, outputBytes, primaryBytes.Length + fragmentBytes1.Length + fragmentBytes2.Length, fragmentBytes3.Length); |
69 | 52 |
|
70 | 53 | var tmpFile = Path.GetTempFileName();
|
71 | 54 | Console.WriteLine("Writing restored primary file at {0}", tmpFile);
|
72 |
| - File.WriteAllBytes(tmpFile, primaryBytes); |
| 55 | + File.WriteAllBytes(tmpFile, outputBytes); |
73 | 56 | Console.WriteLine("Deleting {0}", primaryFile);
|
74 | 57 | File.Delete(primaryFile);
|
75 | 58 | Console.WriteLine("Moving {0} --> {1}", tmpFile, primaryFile);
|
|
0 commit comments