-
Notifications
You must be signed in to change notification settings - Fork 400
Add LoadTarManifest to get the manifest from docker-archive #309
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,23 +145,28 @@ func (s *Source) ensureCachedDataIsPresent() error { | |
| return err | ||
| } | ||
|
|
||
| // Check to make sure length is 1 | ||
| if len(tarManifest) != 1 { | ||
| return errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(tarManifest)) | ||
| } | ||
|
|
||
| // Read and parse config. | ||
| configBytes, err := s.readTarComponent(tarManifest.Config) | ||
| configBytes, err := s.readTarComponent(tarManifest[0].Config) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| var parsedConfig image // Most fields ommitted, we only care about layer DiffIDs. | ||
| if err := json.Unmarshal(configBytes, &parsedConfig); err != nil { | ||
| return errors.Wrapf(err, "Error decoding tar config %s", tarManifest.Config) | ||
| return errors.Wrapf(err, "Error decoding tar config %s", tarManifest[0].Config) | ||
| } | ||
|
|
||
| knownLayers, err := s.prepareLayerData(tarManifest, &parsedConfig) | ||
| knownLayers, err := s.prepareLayerData(&tarManifest[0], &parsedConfig) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Success; commit. | ||
| s.tarManifest = tarManifest | ||
| s.tarManifest = &tarManifest[0] | ||
| s.configBytes = configBytes | ||
| s.configDigest = digest.FromBytes(configBytes) | ||
| s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs | ||
|
|
@@ -170,7 +175,7 @@ func (s *Source) ensureCachedDataIsPresent() error { | |
| } | ||
|
|
||
| // loadTarManifest loads and decodes the manifest.json. | ||
| func (s *Source) loadTarManifest() (*manifestItem, error) { | ||
| func (s *Source) loadTarManifest() ([]manifestItem, error) { | ||
| // FIXME? Do we need to deal with the legacy format? | ||
| bytes, err := s.readTarComponent(manifestFileName) | ||
| if err != nil { | ||
|
|
@@ -180,10 +185,12 @@ func (s *Source) loadTarManifest() (*manifestItem, error) { | |
| if err := json.Unmarshal(bytes, &items); err != nil { | ||
| return nil, errors.Wrap(err, "Error decoding tar manifest.json") | ||
| } | ||
| if len(items) != 1 { | ||
| return nil, errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(items)) | ||
| } | ||
| return &items[0], nil | ||
| return items, nil | ||
| } | ||
|
|
||
| // LoadTarManifest loads and decodes the manifest.json | ||
| func (s *Source) LoadTarManifest() ([]manifestItem, error) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it acceptable to return a private type from a public function? AFAIK the caller won’t be able to refer to the type in parameter/return value declarations. (If it works for you, fine; just make sure that it does.)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is working in her current code.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup it works fine. I looked it up and a private type can be accessed from an exported function, but the private type can't be created outside its own package. |
||
| return s.loadTarManifest() | ||
| } | ||
|
|
||
| func (s *Source) prepareLayerData(tarManifest *manifestItem, parsedConfig *image) (map[diffID]*layerInfo, error) { | ||
|
|
||
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.
This check should remain in place when using
Sourceas atypes.ImageSourcebackend.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.
Can we move it to the other function? The only one that calls this? Then we would only have one loadmanafest function.
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.
@mtrmac I added the error check in ensureCachedDataIsPresent() after loadTarManifest() is being called.
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.
That’s better, sure.