Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for symbolic links for provisioning profiles folder #123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Xamarin.MacDev/MobileProvisionIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ public void Save (string fileName)
}
}

/// <summary>
/// Determines the last write time in UTC for the specified directory path or the target directory if the path is a symbolic link.
/// Returns the latest date of both.
/// </summary>
static DateTime GetLastWriteTimeUtcForPath (string path)
{
var lastWriteTimeUtcForPath = Directory.GetLastWriteTimeUtc (path);

// check symbolic link
var dirInfo = new DirectoryInfo (path);
if (dirInfo.LinkTarget is not null) {
var lastWriteTimeUtcforLink = Directory.GetLastWriteTimeUtc (dirInfo.LinkTarget);
return new DateTime (Math.Max (lastWriteTimeUtcForPath.Ticks, lastWriteTimeUtcforLink.Ticks));
}

return lastWriteTimeUtcForPath;
}

public static MobileProvisionIndex CreateIndex (string profilesDir, string indexName)
{
var index = new MobileProvisionIndex ();
Expand All @@ -286,7 +304,7 @@ public static MobileProvisionIndex CreateIndex (string profilesDir, string index
}

index.Version = IndexVersion;
index.LastModified = Directory.GetLastWriteTimeUtc (profilesDir);
index.LastModified = GetLastWriteTimeUtcForPath (profilesDir);

index.Save (indexName);

Expand All @@ -301,7 +319,7 @@ public static MobileProvisionIndex OpenIndex (string profilesDir, string indexNa
index = Load (indexName);

if (Directory.Exists (profilesDir)) {
var mtime = Directory.GetLastWriteTimeUtc (profilesDir);
var mtime = GetLastWriteTimeUtcForPath (profilesDir);

if (index.Version != IndexVersion) {
index = CreateIndex (profilesDir, indexName);
Expand Down Expand Up @@ -351,7 +369,7 @@ public static MobileProvisionIndex OpenIndex (string profilesDir, string indexNa
foreach (var item in table)
index.ProvisioningProfiles.Remove (item.Value);

index.LastModified = Directory.GetLastWriteTimeUtc (profilesDir);
index.LastModified = GetLastWriteTimeUtcForPath (profilesDir);
index.Version = IndexVersion;

index.ProvisioningProfiles.Sort (CreationDateComparer);
Expand Down