Skip to content

Commit

Permalink
chore: updates comments and adds Close() for io.ReadCloser types used
Browse files Browse the repository at this point in the history
Updates attribution comments and add TODO comments
Adds a defer statement to close io.ReadCloser types return when
unused to avoid leaking resources.

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Oct 14, 2023
1 parent bf72a03 commit 88cdd05
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion manager/defaultmanager/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ func (d DefaultManager) addLinks(ctx context.Context, client registryclient.Clie
d.logger.Infof("Processing %d link(s)", len(links))
var linkedDesc []ocispec.Descriptor
for _, l := range links {
desc, _, err := client.GetManifest(ctx, l)
desc, rc, err := client.GetManifest(ctx, l)
if err != nil {
return nil, fmt.Errorf("link %q: %w", l, err)
}
defer rc.Close()

if desc.Annotations == nil {
desc.Annotations = map[string]string{}
}
Expand Down
2 changes: 1 addition & 1 deletion nodes/collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
//
// Description:
// The following code has been adapted and heavily modified from the original Gonum project
// to suit the needs of this project.
// to suit the needs of this project.

// Collection is implementation of a model Node represent one OCI artifact
// stored in memory.
Expand Down
1 change: 0 additions & 1 deletion nodes/collection/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
// Description:
// The following code has been adapted from the original Gonum project for use in this project.


// Note(jpower432): Could possibly removed or deprecated. I do not believe this is used anywhere.

// InOrderIterator implements the model.Iterator interface and traverse the nodes
Expand Down
4 changes: 4 additions & 0 deletions nodes/collection/loader/manifest_to_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ func addOrGetNode(graph *collection.Collection, desc ocispec.Descriptor) (model.
// The following code has been adapted from the original `oras` project to fit the needs of this project.
// Changes made:
// - Added `FetcherFunc` to allow for custom fetching of content.
// - Added `empspec.MediaTypeCollectionManifest` to allow for loading of collection manifests.
// - Added `empspec.AnnotationLink` to allow for loading of linked manifests.

// TODO: Replace FetcherFunc with upstream
// https://github.com/oras-project/oras-go/blob/86176e8c5e8c63f418ed2f71bead3abe0b5f2ccb/content/storage.go#L75

// getSuccessor returns the nodes directly pointed by the current node. This is adapted from the `oras` content.Successors
// to allow the use of a function signature to pull descriptor content.
Expand Down
2 changes: 1 addition & 1 deletion nodes/descriptor/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func AnnotationsToAttributes(annotations map[string]string) (map[string]json.Raw
}

// AnnotationsFromAttributes converts collection spec attributes to collection annotations
//// for OCI descriptor compatibility.
// // for OCI descriptor compatibility.
func AnnotationsFromAttributes(attributes map[string]json.RawMessage) (map[string]string, error) {
attrJSoN, err := json.Marshal(attributes)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion registryclient/orasclient/oras.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (c *orasClient) LoadCollection(ctx context.Context, reference string) (coll
if err != nil {
return collection.Collection{}, err
}
defer manifestBytes.Close()

// Get manifest information to obtain annotations
var manifest ocispec.Descriptor
Expand Down Expand Up @@ -426,7 +427,7 @@ func (c *orasClient) setupRepo(ref string) (*remote.Repository, error) {
}

// TODO(jpower432): PR upstream so that this can be done with the pre-copy option. Currently the error to skip descriptors is
// private
// private
// Reference: https://github.com/oras-project/oras-go/blob/9e5b1419cdedd6240a5bf836c83f75270ba9d74b/copy.go#L49.

// successorFnWithSparseManifest defines a successor function to use with oras.Copy that will skip any expected linked content (i.e. sparse manifests)
Expand Down

0 comments on commit 88cdd05

Please sign in to comment.