code cleanup

clean up code identified as problematic by golands inspection

Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
baude
2019-07-03 15:37:17 -05:00
parent f7407f2eb5
commit 1d36501f96
19 changed files with 122 additions and 140 deletions

View File

@ -555,7 +555,7 @@ func (c *Container) removeConmonFiles() error {
if !os.IsNotExist(err) {
return errors.Wrapf(err, "error running stat on container %s exit file", c.ID())
}
} else if err == nil {
} else {
// Rename should replace the old exit file (if it exists)
if err := os.Rename(exitFile, oldExitFile); err != nil {
return errors.Wrapf(err, "error renaming container %s exit file", c.ID())
@ -568,11 +568,11 @@ func (c *Container) removeConmonFiles() error {
func (c *Container) export(path string) error {
mountPoint := c.state.Mountpoint
if !c.state.Mounted {
mount, err := c.runtime.store.Mount(c.ID(), c.config.MountLabel)
containerMount, err := c.runtime.store.Mount(c.ID(), c.config.MountLabel)
if err != nil {
return errors.Wrapf(err, "error mounting container %q", c.ID())
}
mountPoint = mount
mountPoint = containerMount
defer func() {
if _, err := c.runtime.store.Unmount(c.ID(), false); err != nil {
logrus.Errorf("error unmounting container %q: %v", c.ID(), err)
@ -856,18 +856,18 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error {
span.SetTag("struct", "container")
defer span.Finish()
// Generate the OCI spec
spec, err := c.generateSpec(ctx)
// Generate the OCI newSpec
newSpec, err := c.generateSpec(ctx)
if err != nil {
return err
}
// Save the OCI spec to disk
if err := c.saveSpec(spec); err != nil {
// Save the OCI newSpec to disk
if err := c.saveSpec(newSpec); err != nil {
return err
}
// With the spec complete, do an OCI create
// With the newSpec complete, do an OCI create
if err := c.ociRuntime.createContainer(c, c.config.CgroupParent, nil); err != nil {
return err
}
@ -1167,8 +1167,8 @@ func (c *Container) cleanupStorage() error {
return nil
}
for _, mount := range c.config.Mounts {
if err := c.unmountSHM(mount); err != nil {
for _, containerMount := range c.config.Mounts {
if err := c.unmountSHM(containerMount); err != nil {
return err
}
}
@ -1399,14 +1399,14 @@ func (c *Container) setupOCIHooks(ctx context.Context, config *spec.Spec) (exten
}
return nil, err
}
hooks, err := manager.Hooks(config, c.Spec().Annotations, len(c.config.UserVolumes) > 0)
ociHooks, err := manager.Hooks(config, c.Spec().Annotations, len(c.config.UserVolumes) > 0)
if err != nil {
return nil, err
}
if len(hooks) > 0 || config.Hooks != nil {
logrus.Warnf("implicit hook directories are deprecated; set --hooks-dir=%q explicitly to continue to load hooks from this directory", hDir)
if len(ociHooks) > 0 || config.Hooks != nil {
logrus.Warnf("implicit hook directories are deprecated; set --ociHooks-dir=%q explicitly to continue to load ociHooks from this directory", hDir)
}
for i, hook := range hooks {
for i, hook := range ociHooks {
allHooks[i] = hook
}
}