Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Pan <[email protected]>
  • Loading branch information
Patrick Pan committed Jan 3, 2025
1 parent 1041bc0 commit a3e6289
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/OrasProject.Oras/Registry/Remote/ManifestStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private async Task ProcessReferrersAndPushIndex(Descriptor desc, Stream content,
return;

Check warning on line 251 in src/OrasProject.Oras/Registry/Remote/ManifestStore.cs

View check run for this annotation

Codecov / codecov/patch

src/OrasProject.Oras/Registry/Remote/ManifestStore.cs#L251

Added line #L251 was not covered by tests
}

Repository.ReferrersState = Referrers.ReferrersState.NotSupported;
Repository.SetReferrersState(false);
await UpdateReferrersIndex(subject, new Referrers.ReferrerChange(desc, Referrers.ReferrerOperation.Add), cancellationToken).ConfigureAwait(false);
}

Expand Down
18 changes: 11 additions & 7 deletions src/OrasProject.Oras/Registry/Remote/Referrers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,41 @@ internal static (IList<Descriptor>, bool) ApplyReferrerChanges(IList<Descriptor>
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)
Expand Down
5 changes: 5 additions & 0 deletions src/OrasProject.Oras/Registry/Remote/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,9 @@ internal Reference ParseReferenceFromContentReference(string reference)
/// <returns></returns>
public async Task MountAsync(Descriptor descriptor, string fromRepository, Func<CancellationToken, Task<Stream>>? 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;
}
}
18 changes: 10 additions & 8 deletions src/OrasProject.Oras/Registry/Remote/RepositoryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public struct RepositoryOptions
/// </summary>
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
/// <summary>
/// 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
/// </summary>
public bool SkipReferrersGc { get; set; }
}

0 comments on commit a3e6289

Please sign in to comment.