Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cp: Fix --from-oci-layout when using full reference #1507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mauriciovasquezbernal
Copy link

What this PR does / why we need it:

Copying an image from an OCI layout with a value like "foo/bar:latest" for "org.opencontainers.image.ref.name" was failing with:

$ oras cp --from-oci-layout ./myimage:foo/bar:latest localhost:5000/foo:latest
Error: invalid argument "./myimage:foo/bar:latest": failed to find path "./myimage:foo/bar:": stat /myimage:foo/bar: no such file or directory

According to 0, foo/bar:latest if a valid value for "org.opencontainers.image.ref.name", so the command should work.

This commit fixes that by using strings.Index() instead of strings.LastIndex().

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1505

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Copying an image from an OCI layout with a value like
"foo/bar:latest" for "org.opencontainers.image.ref.name" was failing with:

```
$ oras cp --from-oci-layout ./myimage:foo/bar:latest localhost:5000/foo:latest
Error: invalid argument "./myimage:foo/bar:latest": failed to find path "./myimage:foo/bar:": stat /myimage:foo/bar: no such file or directory
```

According to [0], foo/bar:latest if a valid value for
"org.opencontainers.image.ref.name", so the command should work.

This commit fixes that by using strings.Index() instead of strings.LastIndex().

[0]: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc5/annotations.md

Signed-off-by: Mauricio Vásquez <[email protected]>
{"Empty digest", "path@", "path", "", false},
{"Empty tag", "path:", "path", "", false},
{"path and digest", "path@digest", "path", "digest", false},
{"path and tag", "path:tag", "path", "tag", false},
{"path with full reference", "path:repo:tag", "path", "repo:tag", false},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the path be path:repo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path:repo fails, but the included content passes

Copy link
Contributor

@sabre1041 sabre1041 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{"Empty digest", "path@", "path", "", false},
{"Empty tag", "path:", "path", "", false},
{"path and digest", "path@digest", "path", "digest", false},
{"path and tag", "path:tag", "path", "tag", false},
{"path with full reference", "path:repo:tag", "path", "repo:tag", false},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path:repo fails, but the included content passes

if err != nil {
return errors.Join(err, errdef.ErrInvalidReference)
}
} else if idx := strings.Index(raw, ":"); idx != -1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if idx := strings.Index(raw, ":"); idx != -1 {
} else if idx := strings.LastIndex(raw, ":"); idx != -1 {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

oras cp fails if org.opencontainers.image.ref.name contains a full reference
3 participants