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

cleanup created bundle when creating failed #172

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

Mashimiao
Copy link

If any error occurs, we should cleanup the bundle we created. If not, this may confuse users.

Signed-off-by: Ma Shimiao [email protected]

image/image.go Outdated
defer func() {
if err != nil {
if err3 := os.RemoveAll(dest); err3 != nil {
fmt.Printf("warning: failed to clean up %q\n", dest)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we wrap err3? I'd like to expose the reason for the failure to the user.

Copy link
Author

Choose a reason for hiding this comment

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

I think we can't, because we can't return any value in defer function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you squash it into err? Or at least print it here?

Copy link
Author

Choose a reason for hiding this comment

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

Let's print it here, updated

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's print it here, updated

Did you forget to push? I still see this PR pointing at c5ed3a8, has a 2017-08-04 commit date.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, my fault. updated.

image/image.go Outdated
@@ -301,6 +301,13 @@ func createBundle(w walker, m *manifest, dest, rootfs string) error {
if err2 := os.MkdirAll(dest, 0755); err2 != nil {
return err2
}
defer func() {
if err != nil {
if err3 := os.RemoveAll(dest); err3 != nil {
Copy link
Member

Choose a reason for hiding this comment

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

With this defer, it may be good to use named returns.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I don't know what you mean. What kind of named return?

Copy link
Member

@coolljt0725 coolljt0725 Aug 23, 2017

Choose a reason for hiding this comment

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

func createBundle(w walker, m *manifest, dest, rootfs string) ( retErr error)

and use

defer func() {
     if retErr != nil {
}
}()

here

Copy link
Author

Choose a reason for hiding this comment

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

It seems still can't return err and err3 at same time.

Copy link
Member

Choose a reason for hiding this comment

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

why err3 need to return?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Fine, updated

@@ -301,6 +301,13 @@ func createBundle(w walker, m *manifest, dest, rootfs string) error {
if err2 := os.MkdirAll(dest, 0755); err2 != nil {
return err2
}
defer func() {
if retErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use err instead of retErr. Otherwise I expect this will always be nil (unless we change to set retErr in the body of createBundle). Or maybe Go does something magic with named returns to set them up before defers fire?

Copy link
Member

Choose a reason for hiding this comment

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

when return ,go will assign the return value to retErr

@coolljt0725
Copy link
Member

coolljt0725 commented Aug 25, 2017

LGTM

Approved with PullApprove

1 similar comment
@zhouhao3
Copy link

zhouhao3 commented Aug 29, 2017

LGTM

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit cfb23a2 into opencontainers:master Aug 29, 2017
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.

4 participants