-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
70e0649
to
c5ed3a8
Compare
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) |
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 wrap err3
? I'd like to expose the reason for the failure to the user.
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.
I think we can't, because we can't return any value in defer 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.
Can you squash it into err
? Or at least print it here?
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.
Let's print it here, updated
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.
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.
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.
Oh, my fault. updated.
c5ed3a8
to
5e6f503
Compare
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 { |
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.
With this defer, it may be good to use named returns.
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.
Sorry, I don't know what you mean. What kind of named return?
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.
func createBundle(w walker, m *manifest, dest, rootfs string) ( retErr error)
and use
defer func() {
if retErr != nil {
}
}()
here
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.
It seems still can't return err and err3 at same time.
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.
why err3
need to return?
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.
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.
Fine, updated
Signed-off-by: Ma Shimiao <[email protected]>
5e6f503
to
4abe1a1
Compare
@@ -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 { |
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 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?
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.
when return ,go will assign the return value to retErr
If any error occurs, we should cleanup the bundle we created. If not, this may confuse users.
Signed-off-by: Ma Shimiao [email protected]