From 93b1de66924a3ca79faaa1f7206eacf6b1b1ae25 Mon Sep 17 00:00:00 2001 From: Christian Schulz Date: Wed, 26 Jun 2024 00:14:09 +0200 Subject: [PATCH 1/2] Add support for symbolic links for provisioning profile folders --- Xamarin.MacDev/MobileProvisionIndex.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Xamarin.MacDev/MobileProvisionIndex.cs b/Xamarin.MacDev/MobileProvisionIndex.cs index 62f5bc3..88c50c7 100644 --- a/Xamarin.MacDev/MobileProvisionIndex.cs +++ b/Xamarin.MacDev/MobileProvisionIndex.cs @@ -263,6 +263,24 @@ public void Save (string fileName) } } + /// + /// 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. + /// + static DateTime GetLastWriteTimeUtcForPath(string path) + { + var lastWriteTimeUtcForPath = Directory.GetLastWriteTimeUtc(path); + + // check symbolic link + var dirInfo = new DirectoryInfo(path); + if ( dirInfo.LinkTarget != 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 (); @@ -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); @@ -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); @@ -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); From e72c1e047987f09eb5994c8b5cbf185bf32e5303 Mon Sep 17 00:00:00 2001 From: Christian Schulz Date: Wed, 26 Jun 2024 23:52:57 +0200 Subject: [PATCH 2/2] format code --- Xamarin.MacDev/MobileProvisionIndex.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Xamarin.MacDev/MobileProvisionIndex.cs b/Xamarin.MacDev/MobileProvisionIndex.cs index 88c50c7..89da278 100644 --- a/Xamarin.MacDev/MobileProvisionIndex.cs +++ b/Xamarin.MacDev/MobileProvisionIndex.cs @@ -267,18 +267,18 @@ public void Save (string fileName) /// 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. /// - static DateTime GetLastWriteTimeUtcForPath(string path) + static DateTime GetLastWriteTimeUtcForPath (string path) { - var lastWriteTimeUtcForPath = Directory.GetLastWriteTimeUtc(path); - + var lastWriteTimeUtcForPath = Directory.GetLastWriteTimeUtc (path); + // check symbolic link - var dirInfo = new DirectoryInfo(path); - if ( dirInfo.LinkTarget != null) { - var lastWriteTimeUtcforLink = Directory.GetLastWriteTimeUtc(dirInfo.LinkTarget); - return new DateTime(Math.Max(lastWriteTimeUtcForPath.Ticks, lastWriteTimeUtcforLink.Ticks)); + 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; + return lastWriteTimeUtcForPath; } public static MobileProvisionIndex CreateIndex (string profilesDir, string indexName)