@@ -31,9 +31,9 @@ namespace UnityNuGet
3131 public class RegistryCache
3232 {
3333 public static readonly bool IsRunningOnAzure = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "WEBSITE_SITE_NAME" ) ) ;
34-
34+
3535 // Change this version number if the content of the packages are changed by an update of this class
36- private const string CurrentRegistryVersion = "1.6 .0" ;
36+ private const string CurrentRegistryVersion = "1.7 .0" ;
3737
3838 private static readonly Encoding Utf8EncodingNoBom = new UTF8Encoding ( false , false ) ;
3939 private readonly string _rootPersistentFolder ;
@@ -209,7 +209,7 @@ private async Task BuildInternal()
209209 // Clear the cache entirely
210210 _npmPackageRegistry . Reset ( ) ;
211211 }
212-
212+
213213 var regexFilter = Filter != null ? new Regex ( Filter , RegexOptions . IgnoreCase ) : null ;
214214 if ( Filter != null )
215215 {
@@ -554,7 +554,10 @@ RegistryEntry packageEntry
554554 using var memStream = new MemoryStream ( ) ;
555555
556556 using ( var outStream = File . Create ( unityPackageFilePath ) )
557- using ( var gzoStream = new GZipOutputStream ( outStream ) )
557+ using ( var gzoStream = new GZipOutputStream ( outStream )
558+ {
559+ ModifiedTime = packageMeta . Published ? . UtcDateTime
560+ } )
558561 using ( var tarArchive = new TarOutputStream ( gzoStream , Encoding . UTF8 ) )
559562 {
560563 // Select the framework version that is the closest or equal to the latest configured framework version
@@ -582,6 +585,7 @@ RegistryEntry packageEntry
582585 var isPackageNetStandard21Assembly = DotNetHelper . IsNetStandard21Assembly ( identity . Id ) ;
583586 var hasMultiNetStandard = collectedItems . Count > 1 ;
584587 var hasOnlyNetStandard21 = collectedItems . Count == 1 && collectedItems . Values . First ( ) . All ( x => x . Name == "netstandard2.1" ) ;
588+ var modTime = packageMeta . Published ? . DateTime ?? DateTime . UnixEpoch ;
585589
586590 if ( isPackageNetStandard21Assembly )
587591 {
@@ -625,7 +629,7 @@ RegistryEntry packageEntry
625629 createdDirectoryList . Add ( processedDirectoryName ) ;
626630
627631 // write meta file for the folder
628- await WriteTextFileToTar ( tarArchive , $ "{ processedDirectoryName } .meta", UnityMeta . GetMetaForFolder ( GetStableGuid ( identity , processedDirectoryName ) ) ) ;
632+ await WriteTextFileToTar ( tarArchive , $ "{ processedDirectoryName } .meta", UnityMeta . GetMetaForFolder ( GetStableGuid ( identity , processedDirectoryName ) ) , modTime ) ;
629633 }
630634 }
631635
@@ -660,25 +664,25 @@ RegistryEntry packageEntry
660664 var buffer = memStream . ToArray ( ) ;
661665
662666 // write content
663- await WriteBufferToTar ( tarArchive , fileInUnityPackage , buffer ) ;
667+ await WriteBufferToTar ( tarArchive , fileInUnityPackage , buffer , modTime ) ;
664668
665669 // write meta file
666- await WriteTextFileToTar ( tarArchive , $ "{ fileInUnityPackage } .meta", meta ) ;
670+ await WriteTextFileToTar ( tarArchive , $ "{ fileInUnityPackage } .meta", meta , modTime ) ;
667671 }
668672
669673 // Write analyzer asmdef
670674 // Check Analyzer Scope section: https://docs.unity3d.com/Manual/roslyn-analyzers.html
671675 var analyzerAsmdef = CreateAnalyzerAmsdef ( identity ) ;
672676 var analyzerAsmdefAsJson = analyzerAsmdef . ToJson ( ) ;
673677 string analyzerAsmdefFileName = $ "{ identity . Id } .asmdef";
674- await WriteTextFileToTar ( tarArchive , analyzerAsmdefFileName , analyzerAsmdefAsJson ) ;
675- await WriteTextFileToTar ( tarArchive , $ "{ analyzerAsmdefFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , analyzerAsmdefFileName ) , ".asmdef" ) ! ) ;
678+ await WriteTextFileToTar ( tarArchive , analyzerAsmdefFileName , analyzerAsmdefAsJson , modTime ) ;
679+ await WriteTextFileToTar ( tarArchive , $ "{ analyzerAsmdefFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , analyzerAsmdefFileName ) , ".asmdef" ) ! , modTime ) ;
676680
677681 // Write empty script (Necessary to compile the asmdef file)
678682 var emptyScriptContent = UnityScript . GetEmptyScript ( ) ;
679683 const string emptyScriptFileName = "EmptyScript.cs" ;
680- await WriteTextFileToTar ( tarArchive , emptyScriptFileName , emptyScriptContent ) ;
681- await WriteTextFileToTar ( tarArchive , $ "{ emptyScriptFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , emptyScriptFileName ) , ".cs" ) ! ) ;
684+ await WriteTextFileToTar ( tarArchive , emptyScriptFileName , emptyScriptContent , modTime ) ;
685+ await WriteTextFileToTar ( tarArchive , $ "{ emptyScriptFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , emptyScriptFileName ) , ".cs" ) ! , modTime ) ;
682686 }
683687
684688 // Get all known platform definitions
@@ -792,10 +796,10 @@ RegistryEntry packageEntry
792796 var buffer = memStream . ToArray ( ) ;
793797
794798 // write content
795- await WriteBufferToTar ( tarArchive , fileInUnityPackage , buffer ) ;
799+ await WriteBufferToTar ( tarArchive , fileInUnityPackage , buffer , modTime ) ;
796800
797801 // write meta file
798- await WriteTextFileToTar ( tarArchive , $ "{ fileInUnityPackage } .meta", meta ) ;
802+ await WriteTextFileToTar ( tarArchive , $ "{ fileInUnityPackage } .meta", meta , modTime ) ;
799803 }
800804 }
801805
@@ -835,8 +839,8 @@ RegistryEntry packageEntry
835839 await stream . CopyToAsync ( memStream ) ;
836840 var buffer = memStream . ToArray ( ) ;
837841
838- await WriteBufferToTar ( tarArchive , file , buffer ) ;
839- await WriteTextFileToTar ( tarArchive , $ "{ file } .meta", meta ) ;
842+ await WriteBufferToTar ( tarArchive , file , buffer , modTime ) ;
843+ await WriteTextFileToTar ( tarArchive , $ "{ file } .meta", meta , modTime ) ;
840844
841845 // Remember all folders for meta files
842846 string folder = string . Empty ;
@@ -850,15 +854,15 @@ RegistryEntry packageEntry
850854
851855 foreach ( var folder in packageFolders )
852856 {
853- await WriteTextFileToTar ( tarArchive , $ "{ folder } .meta", UnityMeta . GetMetaForFolder ( GetStableGuid ( identity , folder ) ) ) ;
857+ await WriteTextFileToTar ( tarArchive , $ "{ folder } .meta", UnityMeta . GetMetaForFolder ( GetStableGuid ( identity , folder ) ) , modTime ) ;
854858 }
855859
856860 // Write the package,json
857861 var unityPackage = CreateUnityPackage ( npmPackageInfo , npmPackageVersion ) ;
858862 var unityPackageAsJson = unityPackage . ToJson ( ) ;
859863 const string packageJsonFileName = "package.json" ;
860- await WriteTextFileToTar ( tarArchive , packageJsonFileName , unityPackageAsJson ) ;
861- await WriteTextFileToTar ( tarArchive , $ "{ packageJsonFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , packageJsonFileName ) , ".json" ) ! ) ;
864+ await WriteTextFileToTar ( tarArchive , packageJsonFileName , unityPackageAsJson , modTime ) ;
865+ await WriteTextFileToTar ( tarArchive , $ "{ packageJsonFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , packageJsonFileName ) , ".json" ) ! , modTime ) ;
862866
863867 // Write the license to the package if any
864868 string ? license = null ;
@@ -912,8 +916,8 @@ RegistryEntry packageEntry
912916 if ( ! string . IsNullOrEmpty ( license ) )
913917 {
914918 const string licenseMdFile = "License.md" ;
915- await WriteTextFileToTar ( tarArchive , licenseMdFile , license ) ;
916- await WriteTextFileToTar ( tarArchive , $ "{ licenseMdFile } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , licenseMdFile ) , ".md" ) ! ) ;
919+ await WriteTextFileToTar ( tarArchive , licenseMdFile , license , modTime ) ;
920+ await WriteTextFileToTar ( tarArchive , $ "{ licenseMdFile } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , licenseMdFile ) , ".md" ) ! , modTime ) ;
917921 }
918922 }
919923
@@ -1042,17 +1046,17 @@ private async Task WritePackageCacheEntry(string packageName, NpmPackageCacheEnt
10421046 }
10431047 }
10441048
1045- private static async Task WriteTextFileToTar ( TarOutputStream tarOut , string filePath , string content , CancellationToken cancellationToken = default )
1049+ private static async Task WriteTextFileToTar ( TarOutputStream tarOut , string filePath , string content , DateTime modTime , CancellationToken cancellationToken = default )
10461050 {
10471051 ArgumentNullException . ThrowIfNull ( tarOut ) ;
10481052 ArgumentNullException . ThrowIfNull ( filePath ) ;
10491053 ArgumentNullException . ThrowIfNull ( content ) ;
10501054
10511055 var buffer = Utf8EncodingNoBom . GetBytes ( content ) ;
1052- await WriteBufferToTar ( tarOut , filePath , buffer , cancellationToken ) ;
1056+ await WriteBufferToTar ( tarOut , filePath , buffer , modTime , cancellationToken ) ;
10531057 }
10541058
1055- private static async Task WriteBufferToTar ( TarOutputStream tarOut , string filePath , byte [ ] buffer , CancellationToken cancellationToken = default )
1059+ private static async Task WriteBufferToTar ( TarOutputStream tarOut , string filePath , byte [ ] buffer , DateTime modTime , CancellationToken cancellationToken = default )
10561060 {
10571061 ArgumentNullException . ThrowIfNull ( tarOut ) ;
10581062 ArgumentNullException . ThrowIfNull ( filePath ) ;
@@ -1062,6 +1066,7 @@ private static async Task WriteBufferToTar(TarOutputStream tarOut, string filePa
10621066 filePath = filePath . TrimStart ( '/' ) ;
10631067
10641068 var tarEntry = TarEntry . CreateTarEntry ( $ "package/{ filePath } ") ;
1069+ tarEntry . ModTime = modTime ;
10651070 tarEntry . Size = buffer . Length ;
10661071 await tarOut . PutNextEntryAsync ( tarEntry , cancellationToken ) ;
10671072 await tarOut . WriteAsync ( buffer , cancellationToken ) ;
@@ -1098,7 +1103,7 @@ private static Guid StringToGuid(string text)
10981103 var hash = SHA1 . HashData ( inputBytes ) ;
10991104 Array . Copy ( hash , 0 , guid , 0 , guid . Length ) ;
11001105
1101- // Follow UUID for SHA1 based GUID
1106+ // Follow UUID for SHA1 based GUID
11021107 const int version = 5 ; // SHA1 (3 for MD5)
11031108 guid [ 6 ] = ( byte ) ( ( guid [ 6 ] & 0x0F ) | ( version << 4 ) ) ;
11041109 guid [ 8 ] = ( byte ) ( ( guid [ 8 ] & 0x3F ) | 0x80 ) ;
0 commit comments