Skip to content

Commit

Permalink
Fixed sorting of Provisioning Profiles in the Index (#18)
Browse files Browse the repository at this point in the history
They were supposed to be reverse sorted by CreationDate.

Also added failure reporting for GetMobileProvision()
  • Loading branch information
jstedfast authored Dec 12, 2017
1 parent 727a1f4 commit 2cff0d7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Xamarin.MacDev/MobileProvisionIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class MobileProvisionCreationDateComparer : IComparer<ProvisioningProfile>
{
public int Compare (ProvisioningProfile x, ProvisioningProfile y)
{
return x.CreationDate.CompareTo (y.CreationDate);
return y.CreationDate.CompareTo (x.CreationDate);
}
}

Expand All @@ -200,7 +200,9 @@ public int Compare (ProvisioningProfile x, ProvisioningProfile y)

public static MobileProvisionIndex Load (string fileName)
{
var previousCreationDate = DateTime.MaxValue;
var index = new MobileProvisionIndex ();
var sorted = true;

using (var stream = File.OpenRead (fileName)) {
using (var reader = new BinaryReader (stream)) {
Expand All @@ -211,8 +213,16 @@ public static MobileProvisionIndex Load (string fileName)
for (int i = 0; i < count; i++) {
var profile = ProvisioningProfile.Load (reader);
index.ProvisioningProfiles.Add (profile);

if (profile.CreationDate > previousCreationDate)
sorted = false;

previousCreationDate = profile.CreationDate;
}

if (!sorted)
index.ProvisioningProfiles.Sort (CreationDateComparer);

return index;
}
}
Expand Down Expand Up @@ -367,8 +377,6 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo
var index = OpenIndex (MobileProvision.ProfileDirectory, IndexFileName);
var latestCreationDate = DateTime.MinValue;

path = null;

foreach (var profile in index.ProvisioningProfiles) {
if (!profile.FileName.EndsWith (extension, StringComparison.Ordinal)) {
failures?.Add ($"The profile '{profile.Name}' is not applicable because its FileName ({profile.FileName}) does not end with '{extension}'.");
Expand All @@ -383,16 +391,10 @@ public static MobileProvision GetMobileProvision (MobileProvisionPlatform platfo
if (name == profile.Name || name == profile.Uuid)
return MobileProvision.LoadFromFile (Path.Combine (MobileProvision.ProfileDirectory, profile.FileName));

if (profile.CreationDate > latestCreationDate) {
path = Path.Combine (MobileProvision.ProfileDirectory, profile.FileName);
latestCreationDate = profile.CreationDate;
}
failures?.Add ($"The profile '{profile.Name}' is not applicable because its Name and Uuid ({profile.Uuid}) do not match '{name}'.");
}

if (path == null)
return null;

return MobileProvision.LoadFromFile (path);
return null;
}

public static IList<MobileProvision> GetMobileProvisions (MobileProvisionPlatform platform, bool includeExpired = false, bool unique = false, List<string> failures = null)
Expand Down

0 comments on commit 2cff0d7

Please sign in to comment.