-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make errSkipDesc
a publicly available error
#487
Conversation
Signed-off-by: razzle <harry@razzle.cloud>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any other data that should be in this error like #482
AFAIK, no. |
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #487 +/- ##
==========================================
+ Coverage 72.92% 73.14% +0.22%
==========================================
Files 49 49
Lines 4528 4528
==========================================
+ Hits 3302 3312 +10
+ Misses 919 911 -8
+ Partials 307 305 -2
|
@Noxsios IMHO, it's better to do this work in only := []string{"hello.txt", "world.txt"}
copyOpts.FindSuccessors = func(ctx context.Context, fetcher content.Fetcher, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
nodes, err := func Successors(ctx, fetcher, desc)
if err != nil {
return nil, err
}
if len(only) == 0 {
return nodes
}
var ret []ocispec.Descriptor
for _, n := range nodes {
if utils.sliceContains(only, n.Annotations[ocispec.AnnotationTitle]) /* or it's a non-leaf node like manifest/index */ {
append(ret, n)
}
}
return ret
}) |
Hi @Noxsios, can you check if @qweeah's suggestion works for you? |
@Wwwsylvia Agreed. I was unaware that |
Looks like that works! Final function looks similar to this in case others want the same behavior. // where optional is a slice of strings
// estimatedBytes is the result of calculating the total size of a OCI artifact
alwaysPull := []string{"zarf.yaml", "checksums.txt", "zarf.yaml.sig"}
toPull = append(optional, alwaysPull...)
copyOpts.FindSuccessors = func(ctx context.Context, fetcher content.Fetcher, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
nodes, err := content.Successors(ctx, fetcher, desc)
if err != nil {
return nil, err
}
var ret []ocispec.Descriptor
for _, node := range nodes {
if utils.SliceContains(toPull, node.Annotations[ocispec.AnnotationTitle]) {
ret = append(ret, node)
} else {
estimatedBytes -= node.Size
}
}
return ret, nil
} estimatedBytes is used in our byte by byte progress bar for download / upload progress |
With this change,
oras.ErrSkipDesc
can be used duringPreCopy
to do custom filtering during copy operations.This error is needed to be public as
errors.New
will always create a new error instance, even if the text is the same, so you cannot utilizeerrors.New("skip descriptor")
.ex (psuedo code):