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

descriptor validation #29

Merged
merged 1 commit into from Oct 6, 2016
Merged

descriptor validation #29

merged 1 commit into from Oct 6, 2016

Conversation

xiekeyang
Copy link
Contributor

@xiekeyang xiekeyang commented Sep 22, 2016

Function (d *descriptor) validate() is for descriptor variable, with which the exact cas file path is clear. So in this function, it is safely to open the target file, needn't to walk again.
Other walking mechanism is working properly, to need overall refactor, so I don't touch them hastily.

This PR refers to #5 , by @wking, on reading file part. I'm not very sure if this PR is valuable to be accepted individually. Otherwise we should close it and wait for #5 , or please @wking amend this PR with his singed-off?

As to me, I hope a cas reading/writing API can be used to code.

Signed-off-by: xiekeyang keyang.xie@gmail.com

cc @wking @stevvooe

Signed-off-by: xiekeyang <keyang.xie@gmail.com>
defer f.Close()

tr := tar.NewReader(f)
loop:
Copy link
Member

Choose a reason for hiding this comment

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

is the named loop entirely needed? I'm not opposed to them, but I don't see any inner loops to distinguish from

Copy link
Contributor Author

@xiekeyang xiekeyang Sep 23, 2016

Choose a reason for hiding this comment

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

@vbatts

loop:
        for {
                hdr, err := tr.Next()
                switch err {
                case io.EOF:
                        break loop
                case nil:
                // success, continue below
                default:
                        return nil, err 
                }   
                if hdr.Name == filepath.Join("blobs", desc.algo(), desc.hash()) &&
                        !hdr.FileInfo().IsDir() {
                        buf, err := ioutil.ReadAll(tr)
                        if err != nil {
                                return nil, err 
                        }   
                        return ioutil.NopCloser(bytes.NewReader(buf)), nil 
                }   
        }   

break is located in switch-case block, but it want to break the for-loop. So it should point the label( as break loop). Otherwise, the break will jump out switch-case block.
Of course, we can use if checking instead of switch-case, which not use label. But it is same effect.
If my explain has covered your question?

Copy link
Member

Choose a reason for hiding this comment

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

You're right. My apologies.

@xiekeyang
Copy link
Contributor Author

PTAL.

@vbatts
Copy link
Member

vbatts commented Sep 27, 2016

LGTM

@vbatts vbatts merged commit 08adc22 into opencontainers:master Oct 6, 2016
@xiekeyang xiekeyang deleted the desc-val branch October 7, 2016 03:06
@wking wking mentioned this pull request Oct 25, 2016
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.

None yet

2 participants