mirror of
https://github.com/containers/podman.git
synced 2025-05-22 09:36:57 +08:00
move defer'd function declaration ahead of prepare error return
Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -46,9 +46,6 @@ func (c *Container) Init(ctx context.Context) (err error) {
|
|||||||
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.prepare(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(ctx); err2 != nil {
|
if err2 := c.cleanup(ctx); err2 != nil {
|
||||||
@ -57,6 +54,10 @@ func (c *Container) Init(ctx context.Context) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := c.prepare(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
// Reinitialize the container
|
// Reinitialize the container
|
||||||
return c.reinit(ctx)
|
return c.reinit(ctx)
|
||||||
@ -99,9 +100,6 @@ func (c *Container) Start(ctx context.Context) (err error) {
|
|||||||
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.prepare(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(ctx); err2 != nil {
|
if err2 := c.cleanup(ctx); err2 != nil {
|
||||||
@ -110,6 +108,10 @@ func (c *Container) Start(ctx context.Context) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := c.prepare(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
// Reinitialize the container if we need to
|
// Reinitialize the container if we need to
|
||||||
if err := c.reinit(ctx); err != nil {
|
if err := c.reinit(ctx); err != nil {
|
||||||
@ -164,9 +166,6 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams,
|
|||||||
return nil, errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
return nil, errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.prepare(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(ctx); err2 != nil {
|
if err2 := c.cleanup(ctx); err2 != nil {
|
||||||
@ -175,6 +174,10 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams,
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := c.prepare(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
// Reinitialize the container if we need to
|
// Reinitialize the container if we need to
|
||||||
if err := c.reinit(ctx); err != nil {
|
if err := c.reinit(ctx); err != nil {
|
||||||
|
@ -623,9 +623,6 @@ func (c *Container) initAndStart(ctx context.Context) (err error) {
|
|||||||
return errors.Wrapf(ErrCtrStateInvalid, "cannot start paused container %s", c.ID())
|
return errors.Wrapf(ErrCtrStateInvalid, "cannot start paused container %s", c.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.prepare(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(ctx); err2 != nil {
|
if err2 := c.cleanup(ctx); err2 != nil {
|
||||||
@ -634,6 +631,10 @@ func (c *Container) initAndStart(ctx context.Context) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := c.prepare(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// If we are ContainerStateStopped we need to remove from runtime
|
// If we are ContainerStateStopped we need to remove from runtime
|
||||||
// And reset to ContainerStateConfigured
|
// And reset to ContainerStateConfigured
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
@ -719,9 +720,6 @@ func (c *Container) restartWithTimeout(ctx context.Context, timeout uint) (err e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := c.prepare(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(ctx); err2 != nil {
|
if err2 := c.cleanup(ctx); err2 != nil {
|
||||||
@ -729,6 +727,9 @@ func (c *Container) restartWithTimeout(ctx context.Context, timeout uint) (err e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
if err := c.prepare(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
// Reinitialize the container if we need to
|
// Reinitialize the container if we need to
|
||||||
|
@ -484,9 +484,6 @@ func (c *Container) restore(ctx context.Context, keep bool) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.prepare(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(ctx); err2 != nil {
|
if err2 := c.cleanup(ctx); err2 != nil {
|
||||||
@ -495,6 +492,10 @@ func (c *Container) restore(ctx context.Context, keep bool) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := c.prepare(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: use existing way to request static IPs, once it is merged in ocicni
|
// TODO: use existing way to request static IPs, once it is merged in ocicni
|
||||||
// https://github.com/cri-o/ocicni/pull/23/
|
// https://github.com/cri-o/ocicni/pull/23/
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user