opencontainers / image-tools

OCI Image Tooling
https://opencontainers.org
Apache License 2.0
266 stars 83 forks source link

image: fix the interaction of findManifest and findConfig with walker.find #206

Open knieriem opened 6 years ago

knieriem commented 6 years ago

Before rev. 9027d58 findManifest and findConfig called w.walk directly, providing a walkFunc that returned errEOW in case a file has been found and processed successfully. A switch construct evaluating the error-result of w.walk then tested for the errEOW case, meaning the file has been found.

Starting with rev. 9027d58 the call to w.walk in findManifest and findConfig has been replaced by w.find. Though, the function literal provided by findManifest and findConfig to w.find -- now a findFunc, not a walkFunc anymore -- still returns errEOW. As a consequence, walker.find implementations for tar and zip would treat errEOW as an error, making oci-image-tool 'validate' and 'create' stop with an error:

<tar-image>: find failed: unable to walk: end of walk

This patch adjusts tarWalker's and zipWalker's implementations of walker.find, using errEOW to stop w.walk early in case of success; there is no need for the 'done' variable anymore. Additionally, places where w.find is called, functions findManifest, unpackManifest, and findConfig, have been adapted so that their findFunc argument to w.find does not return errEOW anymore; instead nil is returned on success. Consequently, the switch constructs now test err for 'nil' instead of 'errEOW', and 'os.ErrNotExist' instead of nil.

Fixes #205

Signed-off-by: Michael Teichgräber mteichgraeber@gmx.de

edtan commented 5 years ago

Just wondering if there's anything blocking this PR? I ran into this issue with some buildkit-generated tars when trying to use the validate and create commands. (I was using this tool to learn more about the OCI specs.) Thanks!