Skip to content

Commit 637c264

Browse files
committed
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 <[email protected]>
1 parent 76e11cf commit 637c264

File tree

5 files changed

+12
-28
lines changed

5 files changed

+12
-28
lines changed

cmd/podman/volumes/prune.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ func prune(cmd *cobra.Command, args []string) error {
6464
if !force {
6565
reader := bufio.NewReader(os.Stdin)
6666
fmt.Println("WARNING! This will remove all volumes not used by at least one container. The following volumes will be removed:")
67-
if err != nil {
68-
return err
69-
}
7067
listOptions.Filter, err = parse.FilterArgumentsIntoFilters(filter)
7168
if err != nil {
7269
return err

libpod/container_internal_common.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -901,25 +901,19 @@ func (c *Container) resolveWorkDir() error {
901901
if !c.config.CreateWorkingDir {
902902
// No need to create it (e.g., `--workdir=/foo`), so let's make sure
903903
// the path exists on the container.
904-
if err != nil {
905-
if os.IsNotExist(err) {
906-
// If resolved Workdir path gets marked as a valid symlink,
907-
// return nil cause this is valid use-case.
908-
if c.isWorkDirSymlink(resolvedWorkdir) {
909-
return nil
910-
}
911-
return fmt.Errorf("workdir %q does not exist on container %s", workdir, c.ID())
904+
if errors.Is(err, os.ErrNotExist) {
905+
// If resolved Workdir path gets marked as a valid symlink,
906+
// return nil cause this is valid use-case.
907+
if c.isWorkDirSymlink(resolvedWorkdir) {
908+
return nil
912909
}
913-
// This might be a serious error (e.g., permission), so
914-
// we need to return the full error.
915-
return fmt.Errorf("detecting workdir %q on container %s: %w", workdir, c.ID(), err)
910+
return fmt.Errorf("workdir %q does not exist on container %s", workdir, c.ID())
916911
}
917-
return nil
912+
// This might be a serious error (e.g., permission), so
913+
// we need to return the full error.
914+
return fmt.Errorf("detecting workdir %q on container %s: %w", workdir, c.ID(), err)
918915
}
919916
if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil {
920-
if os.IsExist(err) {
921-
return nil
922-
}
923917
return fmt.Errorf("creating container %s workdir: %w", c.ID(), err)
924918
}
925919

@@ -1192,7 +1186,7 @@ func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
11921186
return fmt.Errorf("exporting root file-system diff for %q: %w", c.ID(), err)
11931187
}
11941188

1195-
addToTarFiles, err := crutils.CRCreateRootFsDiffTar(&rootFsChanges, c.state.Mountpoint, c.bundlePath())
1189+
addToTarFiles, err = crutils.CRCreateRootFsDiffTar(&rootFsChanges, c.state.Mountpoint, c.bundlePath())
11961190
if err != nil {
11971191
return err
11981192
}

libpod/runtime_pod_common.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ func (r *Runtime) NewPod(ctx context.Context, p specgen.PodSpecGenerator, option
9090
break
9191
}
9292
}
93-
if addPodErr != nil {
94-
return nil, fmt.Errorf("adding pod to state: %w", addPodErr)
95-
}
96-
97-
return pod, nil
93+
return nil, fmt.Errorf("adding pod to state: %w", addPodErr)
9894
}
9995

10096
// AddInfra adds the created infra container to the pod state

pkg/domain/infra/abi/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ func (ir *ImageEngine) Scp(ctx context.Context, src, dst string, opts entities.I
785785
if err != nil {
786786
return nil, err
787787
}
788-
if (report.LoadReport == nil && err == nil) && (report.Source != nil && report.Dest != nil) { // we need to execute the transfer
788+
if report.LoadReport == nil && (report.Source != nil && report.Dest != nil) { // we need to execute the transfer
789789
transferOpts := entities.ScpTransferOptions{}
790790
transferOpts.ParentFlags = report.ParentFlags
791791
_, err := Transfer(ctx, *report.Source, *report.Dest, transferOpts)

pkg/machine/ocipull/source.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ func GetLocalBlob(ctx context.Context, path string) (*types.BlobInfo, error) {
3535
return nil, err
3636
}
3737
blobs := img.LayerInfos()
38-
if err != nil {
39-
return nil, err
40-
}
4138
if len(blobs) != 1 {
4239
return nil, errors.New("invalid disk image")
4340
}

0 commit comments

Comments
 (0)