fix issues found by nilness

The conditions are always true so they can be removed. And in the case
of exportCheckpoint() the scope means addToTarFiles was overwritten and
thus when it looped over it later the slice was always empty.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2025-05-13 17:18:13 +02:00
parent 76e11cf5fc
commit 637c264e2e
5 changed files with 12 additions and 28 deletions

View File

@ -64,9 +64,6 @@ func prune(cmd *cobra.Command, args []string) error {
if !force { if !force {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
fmt.Println("WARNING! This will remove all volumes not used by at least one container. The following volumes will be removed:") fmt.Println("WARNING! This will remove all volumes not used by at least one container. The following volumes will be removed:")
if err != nil {
return err
}
listOptions.Filter, err = parse.FilterArgumentsIntoFilters(filter) listOptions.Filter, err = parse.FilterArgumentsIntoFilters(filter)
if err != nil { if err != nil {
return err return err

View File

@ -901,8 +901,7 @@ func (c *Container) resolveWorkDir() error {
if !c.config.CreateWorkingDir { if !c.config.CreateWorkingDir {
// No need to create it (e.g., `--workdir=/foo`), so let's make sure // No need to create it (e.g., `--workdir=/foo`), so let's make sure
// the path exists on the container. // the path exists on the container.
if err != nil { if errors.Is(err, os.ErrNotExist) {
if os.IsNotExist(err) {
// If resolved Workdir path gets marked as a valid symlink, // If resolved Workdir path gets marked as a valid symlink,
// return nil cause this is valid use-case. // return nil cause this is valid use-case.
if c.isWorkDirSymlink(resolvedWorkdir) { if c.isWorkDirSymlink(resolvedWorkdir) {
@ -914,12 +913,7 @@ func (c *Container) resolveWorkDir() error {
// we need to return the full error. // we need to return the full error.
return fmt.Errorf("detecting workdir %q on container %s: %w", workdir, c.ID(), err) return fmt.Errorf("detecting workdir %q on container %s: %w", workdir, c.ID(), err)
} }
return nil
}
if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil { if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil {
if os.IsExist(err) {
return nil
}
return fmt.Errorf("creating container %s workdir: %w", c.ID(), err) return fmt.Errorf("creating container %s workdir: %w", c.ID(), err)
} }
@ -1192,7 +1186,7 @@ func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
return fmt.Errorf("exporting root file-system diff for %q: %w", c.ID(), err) return fmt.Errorf("exporting root file-system diff for %q: %w", c.ID(), err)
} }
addToTarFiles, err := crutils.CRCreateRootFsDiffTar(&rootFsChanges, c.state.Mountpoint, c.bundlePath()) addToTarFiles, err = crutils.CRCreateRootFsDiffTar(&rootFsChanges, c.state.Mountpoint, c.bundlePath())
if err != nil { if err != nil {
return err return err
} }

View File

@ -90,13 +90,9 @@ func (r *Runtime) NewPod(ctx context.Context, p specgen.PodSpecGenerator, option
break break
} }
} }
if addPodErr != nil {
return nil, fmt.Errorf("adding pod to state: %w", addPodErr) return nil, fmt.Errorf("adding pod to state: %w", addPodErr)
} }
return pod, nil
}
// AddInfra adds the created infra container to the pod state // AddInfra adds the created infra container to the pod state
func (r *Runtime) AddInfra(ctx context.Context, pod *Pod, infraCtr *Container) (*Pod, error) { func (r *Runtime) AddInfra(ctx context.Context, pod *Pod, infraCtr *Container) (*Pod, error) {
if !r.valid { if !r.valid {

View File

@ -785,7 +785,7 @@ func (ir *ImageEngine) Scp(ctx context.Context, src, dst string, opts entities.I
if err != nil { if err != nil {
return nil, err return nil, err
} }
if (report.LoadReport == nil && err == nil) && (report.Source != nil && report.Dest != nil) { // we need to execute the transfer if report.LoadReport == nil && (report.Source != nil && report.Dest != nil) { // we need to execute the transfer
transferOpts := entities.ScpTransferOptions{} transferOpts := entities.ScpTransferOptions{}
transferOpts.ParentFlags = report.ParentFlags transferOpts.ParentFlags = report.ParentFlags
_, err := Transfer(ctx, *report.Source, *report.Dest, transferOpts) _, err := Transfer(ctx, *report.Source, *report.Dest, transferOpts)

View File

@ -35,9 +35,6 @@ func GetLocalBlob(ctx context.Context, path string) (*types.BlobInfo, error) {
return nil, err return nil, err
} }
blobs := img.LayerInfos() blobs := img.LayerInfos()
if err != nil {
return nil, err
}
if len(blobs) != 1 { if len(blobs) != 1 {
return nil, errors.New("invalid disk image") return nil, errors.New("invalid disk image")
} }