From d627839747e27f0b6986fa0da7bf375d54afafdd Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 11:32:16 -0400 Subject: [PATCH 1/6] Add parsing of CreationDate --- .../Metadata/Parsers/UpdateParser.cs | 18 +++++++++- .../Metadata/UpdateBase.cs | 34 +++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs b/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs index 62ed01f4..55809727 100644 --- a/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs +++ b/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs @@ -26,7 +26,23 @@ public static string GetDescription(XPathNavigator metadataNavigator, XmlNamespa } } - public static string GetTitle(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager) + public static DateTime GetCreationDate(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager) + { + XPathExpression updateTypeQuery = metadataNavigator.Compile("upd:Update/upd:Properties/@CreationDate"); + updateTypeQuery.SetContext(namespaceManager); + + var result = metadataNavigator.Evaluate(updateTypeQuery) as XPathNodeIterator; + + if (result.Count == 0) + { + throw new Exception("Invalid XML"); + } + + result.MoveNext(); + return DateTime.Parse(result.Current.Value); + } + + public static string GetTitle(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager) { XPathExpression titleQuery = metadataNavigator.Compile("upd:Update/upd:LocalizedPropertiesCollection/upd:LocalizedProperties[upd:Language='en']/upd:Title"); titleQuery.SetContext(namespaceManager); diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index 23af3ae6..84fd61b1 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -177,13 +177,33 @@ public string Description } private string _Description = null; - /// - /// Gets the list of files (content) for update - /// - /// - /// List of content files - /// - public IEnumerable Files + /// + /// Get the category or update creation date + /// + public DateTime CreationDate + { + get + { + if (_MetadataLoaded) + { + return _CreationDate; + } + else + { + LoadNonIndexedMetadataBase(); + return _CreationDate; + } + } + } + private string _CreationDate = null; + + /// + /// Gets the list of files (content) for update + /// + /// + /// List of content files + /// + public IEnumerable Files { get { From c0f9f8255460b797004e77e469933358686df867 Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 11:36:24 -0400 Subject: [PATCH 2/6] Fix type of CreationDate property --- src/microsoft-update-partition/Metadata/UpdateBase.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index 84fd61b1..a5ba75bf 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -484,7 +484,8 @@ internal MicrosoftUpdatePackage(MicrosoftUpdatePackageIdentity id, XPathNavigato _TitleLoaded = true; _Description = UpdateParser.GetDescription(metadataNavigator, namespaceManager); - _MetadataLoaded = true; + _CreationDate = UpdateParser.GetCreationDate(metadataNavigator, namespaceManager); + _MetadataLoaded = true; _Prerequisites = PrerequisiteParser.FromXml(metadataNavigator, namespaceManager); _PrerequisitesLoaded = true; @@ -605,7 +606,8 @@ internal void LoadNonIndexedMetadataBase() manager.AddNamespace("wsi", "http://schemas.microsoft.com/msus/2002/12/UpdateHandlers/WindowsSetup"); _Description = UpdateParser.GetDescription(navigator, manager); - _Title = UpdateParser.GetTitle(navigator, manager); + _CreationDate = UpdateParser.GetCreationDate(navigator, manager); + _Title = UpdateParser.GetTitle(navigator, manager); LoadNonIndexedMetadata(navigator, manager); } From d2db55237b16f925c9921d5b672f848e3bca5088 Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 16:51:18 -0400 Subject: [PATCH 3/6] Add indexing of Descriptions from metadata --- .../Partitions/PartitionRegistration.cs | 2 +- .../Storage/Index/DescriptionsIndex.cs | 33 +++++++++++++++++++ .../PackageGraph/Storage/Index/IndexTypes.cs | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs diff --git a/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs b/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs index 0c4834f8..114fd51f 100644 --- a/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs +++ b/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs @@ -20,7 +20,7 @@ class PartitionRegistration { Factory = null, HasExternalContentFileMetadata = false, - Indexes = new List() { TitlesIndex.TitlesIndexDefinition }, + Indexes = new List() { TitlesIndex.TitlesIndexDefinition, DescriptionsIndex.DescriptionsIndexDefinition }, HandlesIdentities = false, } }, diff --git a/src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs b/src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs new file mode 100644 index 00000000..d1bd5e15 --- /dev/null +++ b/src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs @@ -0,0 +1,33 @@ +using Microsoft.PackageGraph.ObjectModel; + +namespace Microsoft.PackageGraph.Storage.Index +{ + class DescriptionsIndex : SimpleIndex, ISimpleMetadataIndex + { + internal static readonly IndexDefinition DescriptionsIndexDefinition = + new() + { + Name = AvailableIndexes.DescriptionsIndexName, + PartitionName = null, + Version = DescriptionsIndex.CurrentVersion, + Factory = new InternalIndexFactory(), + Tag = "stream" + }; + + public override IndexDefinition Definition => DescriptionsIndexDefinition; + + public DescriptionsIndex(IIndexContainer container) : base(container, AvailableIndexes.TitlesIndexName) + { + } + + public override void IndexPackage(IPackage package, int packageIndex) + { + Add(packageIndex, package.Description); + } + + public new bool TryGet(int packageIndex, out string description) + { + return base.TryGet(packageIndex, out description); + } + } +} diff --git a/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs b/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs index e63ca78e..96fcbf45 100644 --- a/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs +++ b/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs @@ -8,6 +8,7 @@ namespace Microsoft.PackageGraph.Storage.Index abstract class AvailableIndexes { public const string TitlesIndexName = "titles"; + public const string DescriptionsIndexName = "descriptions"; } class InternalIndexFactory : IIndexFactory @@ -17,6 +18,7 @@ public IIndex CreateIndex(IndexDefinition definition, IIndexContainer container) return definition.Name switch { AvailableIndexes.TitlesIndexName => new TitlesIndex(container), + AvailableIndexes.DescriptionsIndexName => new DescriptionsIndex(container), _ => throw new NotImplementedException(), }; } From 68ad76084d77c505c2352b31b23cb7bb42e3a9da Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 22:49:20 -0400 Subject: [PATCH 4/6] Added index lookup logic to Description --- .../Metadata/UpdateBase.cs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index 23af3ae6..cb659788 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -164,18 +164,29 @@ public string Description { get { - if (_MetadataLoaded) + if (_DescriptionLoaded) { return _Description; } - else - { - LoadNonIndexedMetadataBase(); - return _Description; - } - } + else if (_FastLookupSource != null) + { + _FastLookupSource.TrySimpleKeyLookup(_Id, Storage.Index.AvailableIndexes.DescriptionsIndexName, out string description); + return description; + } + else if (_MetadataSource != null) + { + LoadNonIndexedMetadataBase(); + _DescriptionLoaded = true; + return _Description; + } + else + { + return null; + } + } } - private string _Description = null; + private bool _DescriptionLoaded; + private string _Description = null; /// /// Gets the list of files (content) for update From 14eeffeb9f323057f746ecc65523118deeaa0da8 Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 22:53:44 -0400 Subject: [PATCH 5/6] Set Description loaded in constructor --- src/microsoft-update-partition/Metadata/UpdateBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index cb659788..5fad9b32 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -475,6 +475,7 @@ internal MicrosoftUpdatePackage(MicrosoftUpdatePackageIdentity id, XPathNavigato _TitleLoaded = true; _Description = UpdateParser.GetDescription(metadataNavigator, namespaceManager); + _DescriptionLoaded = true; _MetadataLoaded = true; _Prerequisites = PrerequisiteParser.FromXml(metadataNavigator, namespaceManager); From 3bc3a222e945e03eb7cbacaed7df8bba6cccf5f1 Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Mon, 7 Aug 2023 08:56:05 -0400 Subject: [PATCH 6/6] Add CreationDate as an indexed property Change CreationDate type to be string for compatability with SimpleIndex --- .../microsoft-update-partition.xml | 10 ++++++ .../Metadata/Parsers/UpdateParser.cs | 4 +-- .../Metadata/UpdateBase.cs | 20 +++++++++-- .../PackageGraph/ObjectModel/IPackage.cs | 5 +++ .../Partitions/PartitionRegistration.cs | 2 +- .../Storage/Index/CreationDatesIndex.cs | 33 +++++++++++++++++++ .../PackageGraph/Storage/Index/IndexTypes.cs | 2 ++ 7 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 src/microsoft-update-partition/PackageGraph/Storage/Index/CreationDatesIndex.cs diff --git a/src/documentation/xml-autogenerated/microsoft-update-partition.xml b/src/documentation/xml-autogenerated/microsoft-update-partition.xml index 5a7ba53f..a1078362 100644 --- a/src/documentation/xml-autogenerated/microsoft-update-partition.xml +++ b/src/documentation/xml-autogenerated/microsoft-update-partition.xml @@ -1718,6 +1718,11 @@ Get the category or update description + + + Get the category or update creation date + + Gets the list of files (content) for update @@ -2000,6 +2005,11 @@ Get the package description + + + Get the package creation date + + Gets the list of files (content) for a package diff --git a/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs b/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs index 55809727..2d70db69 100644 --- a/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs +++ b/src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs @@ -26,7 +26,7 @@ public static string GetDescription(XPathNavigator metadataNavigator, XmlNamespa } } - public static DateTime GetCreationDate(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager) + public static string GetCreationDate(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager) { XPathExpression updateTypeQuery = metadataNavigator.Compile("upd:Update/upd:Properties/@CreationDate"); updateTypeQuery.SetContext(namespaceManager); @@ -39,7 +39,7 @@ public static DateTime GetCreationDate(XPathNavigator metadataNavigator, XmlName } result.MoveNext(); - return DateTime.Parse(result.Current.Value); + return result.Current.Value; } public static string GetTitle(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager) diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index a5ba75bf..47f7ae55 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -180,21 +180,32 @@ public string Description /// /// Get the category or update creation date /// - public DateTime CreationDate + public string CreationDate { get { - if (_MetadataLoaded) + if (_CreationDateLoaded) { return _CreationDate; } - else + else if (_FastLookupSource != null) + { + _FastLookupSource.TrySimpleKeyLookup(_Id, Storage.Index.AvailableIndexes.CreationDatesIndexName, out string creationdate); + return creationdate; + } + else if (_MetadataSource != null) { LoadNonIndexedMetadataBase(); + _CreationDateLoaded = true; return _CreationDate; } + else + { + return null; + } } } + private bool _CreationDateLoaded; private string _CreationDate = null; /// @@ -484,7 +495,10 @@ internal MicrosoftUpdatePackage(MicrosoftUpdatePackageIdentity id, XPathNavigato _TitleLoaded = true; _Description = UpdateParser.GetDescription(metadataNavigator, namespaceManager); + _CreationDate = UpdateParser.GetCreationDate(metadataNavigator, namespaceManager); + _CreationDateLoaded = true; + _MetadataLoaded = true; _Prerequisites = PrerequisiteParser.FromXml(metadataNavigator, namespaceManager); diff --git a/src/microsoft-update-partition/PackageGraph/ObjectModel/IPackage.cs b/src/microsoft-update-partition/PackageGraph/ObjectModel/IPackage.cs index 7bf9d0dd..368b88e1 100644 --- a/src/microsoft-update-partition/PackageGraph/ObjectModel/IPackage.cs +++ b/src/microsoft-update-partition/PackageGraph/ObjectModel/IPackage.cs @@ -26,6 +26,11 @@ public interface IPackage /// string Description { get; } + /// + /// Get the package creation date + /// + string CreationDate { get; } + /// /// Gets the list of files (content) for a package /// diff --git a/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs b/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs index 0c4834f8..177e2113 100644 --- a/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs +++ b/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs @@ -20,7 +20,7 @@ class PartitionRegistration { Factory = null, HasExternalContentFileMetadata = false, - Indexes = new List() { TitlesIndex.TitlesIndexDefinition }, + Indexes = new List() { TitlesIndex.TitlesIndexDefinition, CreationDatesIndex.CreationDatesIndexDefinition }, HandlesIdentities = false, } }, diff --git a/src/microsoft-update-partition/PackageGraph/Storage/Index/CreationDatesIndex.cs b/src/microsoft-update-partition/PackageGraph/Storage/Index/CreationDatesIndex.cs new file mode 100644 index 00000000..7c50e38a --- /dev/null +++ b/src/microsoft-update-partition/PackageGraph/Storage/Index/CreationDatesIndex.cs @@ -0,0 +1,33 @@ +using Microsoft.PackageGraph.ObjectModel; + +namespace Microsoft.PackageGraph.Storage.Index +{ + class CreationDatesIndex : SimpleIndex, ISimpleMetadataIndex + { + internal static readonly IndexDefinition CreationDatesIndexDefinition = + new() + { + Name = AvailableIndexes.CreationDatesIndexName, + PartitionName = null, + Version = CreationDatesIndex.CurrentVersion, + Factory = new InternalIndexFactory(), + Tag = "stream" + }; + + public override IndexDefinition Definition => CreationDatesIndexDefinition; + + public CreationDatesIndex(IIndexContainer container) : base(container, AvailableIndexes.CreationDatesIndexName) + { + } + + public override void IndexPackage(IPackage package, int packageIndex) + { + Add(packageIndex, package.CreationDate); + } + + public new bool TryGet(int packageIndex, out string creationDate) + { + return base.TryGet(packageIndex, out creationDate); + } + } +} diff --git a/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs b/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs index e63ca78e..87d1049e 100644 --- a/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs +++ b/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs @@ -8,6 +8,7 @@ namespace Microsoft.PackageGraph.Storage.Index abstract class AvailableIndexes { public const string TitlesIndexName = "titles"; + public const string CreationDatesIndexName = "creationDates"; } class InternalIndexFactory : IIndexFactory @@ -17,6 +18,7 @@ public IIndex CreateIndex(IndexDefinition definition, IIndexContainer container) return definition.Name switch { AvailableIndexes.TitlesIndexName => new TitlesIndex(container), + AvailableIndexes.CreationDatesIndexName => new CreationDatesIndex(container), _ => throw new NotImplementedException(), }; }