Skip to content

Commit 05e5efb

Browse files
committed
refactor: Remove redundant check for length
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent 9c21e15 commit 05e5efb

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

cmd/limactl/disk.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,9 @@ func diskDeleteAction(cmd *cobra.Command, args []string) error {
253253
}
254254
var refInstances []string
255255
for _, inst := range instances {
256-
if len(inst.AdditionalDisks) > 0 {
257-
for _, d := range inst.AdditionalDisks {
258-
if d.Name == diskName {
259-
refInstances = append(refInstances, inst.Name)
260-
}
256+
for _, d := range inst.AdditionalDisks {
257+
if d.Name == diskName {
258+
refInstances = append(refInstances, inst.Name)
261259
}
262260
}
263261
}

pkg/osutil/dns_darwin.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ func DNSAddresses() ([]string, error) {
1414
return nil, err
1515
}
1616
var addresses []string
17-
if len(nwData) > 0 {
18-
// Return DNS addresses from the first interface that has an IPv4 address.
19-
// The networks are in service order already.
20-
for _, nw := range nwData {
21-
if len(nw.IPv4.Addresses) > 0 {
22-
addresses = nw.DNS.ServerAddresses
23-
break
24-
}
17+
// Return DNS addresses from the first interface that has an IPv4 address.
18+
// The networks are in service order already.
19+
for _, nw := range nwData {
20+
if len(nw.IPv4.Addresses) > 0 {
21+
addresses = nw.DNS.ServerAddresses
22+
break
2523
}
2624
}
2725
return addresses, nil

pkg/qemu/qemu.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -634,35 +634,33 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
634634
baseDisk := filepath.Join(cfg.InstanceDir, filenames.BaseDisk)
635635
diffDisk := filepath.Join(cfg.InstanceDir, filenames.DiffDisk)
636636
extraDisks := []string{}
637-
if len(y.AdditionalDisks) > 0 {
638-
for _, d := range y.AdditionalDisks {
639-
diskName := d.Name
640-
disk, err := store.InspectDisk(diskName)
641-
if err != nil {
642-
logrus.Errorf("could not load disk %q: %q", diskName, err)
643-
return "", nil, err
644-
}
637+
for _, d := range y.AdditionalDisks {
638+
diskName := d.Name
639+
disk, err := store.InspectDisk(diskName)
640+
if err != nil {
641+
logrus.Errorf("could not load disk %q: %q", diskName, err)
642+
return "", nil, err
643+
}
645644

646-
if disk.Instance != "" {
647-
if disk.InstanceDir != cfg.InstanceDir {
648-
logrus.Errorf("could not attach disk %q, in use by instance %q", diskName, disk.Instance)
649-
return "", nil, err
650-
}
651-
err = disk.Unlock()
652-
if err != nil {
653-
logrus.Errorf("could not unlock disk %q to reuse in the same instance %q", diskName, cfg.Name)
654-
return "", nil, err
655-
}
645+
if disk.Instance != "" {
646+
if disk.InstanceDir != cfg.InstanceDir {
647+
logrus.Errorf("could not attach disk %q, in use by instance %q", diskName, disk.Instance)
648+
return "", nil, err
656649
}
657-
logrus.Infof("Mounting disk %q on %q", diskName, disk.MountPoint)
658-
err = disk.Lock(cfg.InstanceDir)
650+
err = disk.Unlock()
659651
if err != nil {
660-
logrus.Errorf("could not lock disk %q: %q", diskName, err)
652+
logrus.Errorf("could not unlock disk %q to reuse in the same instance %q", diskName, cfg.Name)
661653
return "", nil, err
662654
}
663-
dataDisk := filepath.Join(disk.Dir, filenames.DataDisk)
664-
extraDisks = append(extraDisks, dataDisk)
665655
}
656+
logrus.Infof("Mounting disk %q on %q", diskName, disk.MountPoint)
657+
err = disk.Lock(cfg.InstanceDir)
658+
if err != nil {
659+
logrus.Errorf("could not lock disk %q: %q", diskName, err)
660+
return "", nil, err
661+
}
662+
dataDisk := filepath.Join(disk.Dir, filenames.DataDisk)
663+
extraDisks = append(extraDisks, dataDisk)
666664
}
667665

668666
isBaseDiskCDROM, err := iso9660util.IsISO9660(baseDisk)

0 commit comments

Comments
 (0)