From a3e6289cffefbfa9d7212370580f45d9071e790c Mon Sep 17 00:00:00 2001 From: Patrick Pan Date: Fri, 3 Jan 2025 18:08:50 +1100 Subject: [PATCH] resolve comments Signed-off-by: Patrick Pan --- .../Remote/HttpResponseMessageExtensions.cs | 2 +- .../Registry/Remote/ManifestStore.cs | 2 +- .../Registry/Remote/Referrers.cs | 18 +++++++++++------- .../Registry/Remote/Repository.cs | 5 +++++ .../Registry/Remote/RepositoryOptions.cs | 18 ++++++++++-------- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/OrasProject.Oras/Registry/Remote/HttpResponseMessageExtensions.cs b/src/OrasProject.Oras/Registry/Remote/HttpResponseMessageExtensions.cs index b7a98f6..58239d9 100644 --- a/src/OrasProject.Oras/Registry/Remote/HttpResponseMessageExtensions.cs +++ b/src/OrasProject.Oras/Registry/Remote/HttpResponseMessageExtensions.cs @@ -113,7 +113,7 @@ internal static void CheckOciSubjectHeader(this HttpResponseMessage response, Re if (repository.ReferrersState == Referrers.ReferrersState.Unknown && response.Headers.Contains("OCI-Subject")) { // Set it to Supported when the response header contains OCI-Subject - repository.ReferrersState = Referrers.ReferrersState.Supported; + repository.SetReferrersState(true); } // If the "OCI-Subject" header is NOT set, it means that either the manifest diff --git a/src/OrasProject.Oras/Registry/Remote/ManifestStore.cs b/src/OrasProject.Oras/Registry/Remote/ManifestStore.cs index 9847827..5c77374 100644 --- a/src/OrasProject.Oras/Registry/Remote/ManifestStore.cs +++ b/src/OrasProject.Oras/Registry/Remote/ManifestStore.cs @@ -251,7 +251,7 @@ private async Task ProcessReferrersAndPushIndex(Descriptor desc, Stream content, return; } - Repository.ReferrersState = Referrers.ReferrersState.NotSupported; + Repository.SetReferrersState(false); await UpdateReferrersIndex(subject, new Referrers.ReferrerChange(desc, Referrers.ReferrerOperation.Add), cancellationToken).ConfigureAwait(false); } diff --git a/src/OrasProject.Oras/Registry/Remote/Referrers.cs b/src/OrasProject.Oras/Registry/Remote/Referrers.cs index 724105b..71639a1 100644 --- a/src/OrasProject.Oras/Registry/Remote/Referrers.cs +++ b/src/OrasProject.Oras/Registry/Remote/Referrers.cs @@ -70,37 +70,41 @@ internal static (IList, bool) ApplyReferrerChanges(IList updateRequired = true; continue; } + var basicDesc = oldReferrer.BasicDescriptor; - if (updatedReferrersSet.Contains(basicDesc)) + if (referrerChange.ReferrerOperation == ReferrerOperation.Delete && Equals(basicDesc, referrerChange.Referrer.BasicDescriptor)) { - // Skip any duplicate referrers updateRequired = true; continue; } - // Update the updatedReferrers list - // Add referrer index in the updatedReferrersSet - if (referrerChange.ReferrerOperation == ReferrerOperation.Delete && Descriptor.Equals(basicDesc, referrerChange.Referrer.BasicDescriptor)) + + if (updatedReferrersSet.Contains(basicDesc)) { + // Skip any duplicate referrers updateRequired = true; continue; } + + // Update the updatedReferrers list + // Add referrer into the updatedReferrersSet updatedReferrers.Add(oldReferrer); updatedReferrersSet.Add(basicDesc); } - var basicReferrerDesc = referrerChange.Referrer.BasicDescriptor; if (referrerChange.ReferrerOperation == ReferrerOperation.Add) { + var basicReferrerDesc = referrerChange.Referrer.BasicDescriptor; if (!updatedReferrersSet.Contains(basicReferrerDesc)) { // Add the new referrer only when it has not already existed in the updatedReferrersSet updatedReferrers.Add(referrerChange.Referrer); updatedReferrersSet.Add(basicReferrerDesc); + updateRequired = true; } } // Skip unnecessary update - if (!updateRequired && updatedReferrersSet.Count == oldReferrers.Count) + if (!updateRequired) { // Check for any new referrers in the updatedReferrersSet that are not present in the oldReferrers list foreach (var oldReferrer in oldReferrers) diff --git a/src/OrasProject.Oras/Registry/Remote/Repository.cs b/src/OrasProject.Oras/Registry/Remote/Repository.cs index 742dcc6..fd312f8 100644 --- a/src/OrasProject.Oras/Registry/Remote/Repository.cs +++ b/src/OrasProject.Oras/Registry/Remote/Repository.cs @@ -368,4 +368,9 @@ internal Reference ParseReferenceFromContentReference(string reference) /// public async Task MountAsync(Descriptor descriptor, string fromRepository, Func>? getContent = null, CancellationToken cancellationToken = default) => await ((IMounter)Blobs).MountAsync(descriptor, fromRepository, getContent, cancellationToken).ConfigureAwait(false); + + public void SetReferrersState(bool isSupported) + { + ReferrersState = isSupported ? Referrers.ReferrersState.Supported : Referrers.ReferrersState.NotSupported; + } } diff --git a/src/OrasProject.Oras/Registry/Remote/RepositoryOptions.cs b/src/OrasProject.Oras/Registry/Remote/RepositoryOptions.cs index 77f8259..63e9a5b 100644 --- a/src/OrasProject.Oras/Registry/Remote/RepositoryOptions.cs +++ b/src/OrasProject.Oras/Registry/Remote/RepositoryOptions.cs @@ -51,13 +51,15 @@ public struct RepositoryOptions /// public int TagListPageSize { get; set; } - // SkipReferrersGc specifies whether to delete the dangling referrers - // index when referrers tag schema is utilized. - // - If false, the old referrers index will be deleted after the new one is successfully uploaded. - // - If true, the old referrers index is kept. - // By default, it is disabled (set to false). See also: - // - https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#referrers-tag-schema - // - https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#pushing-manifests-with-subject - // - https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#deleting-manifests + /// + /// SkipReferrersGc specifies whether to delete the dangling referrers + /// index when referrers tag schema is utilized. + /// - If false, the old referrers index will be deleted after the new one is successfully uploaded. + /// - If true, the old referrers index is kept. + /// By default, it is disabled (set to false). See also: + /// - https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#referrers-tag-schema + /// - https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#pushing-manifests-with-subject + /// - https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#deleting-manifests + /// public bool SkipReferrersGc { get; set; } }