dont list empty ones

pull/6695/head
Medya Gh 2020-02-19 15:22:22 -08:00
parent d84aa9f447
commit 6c94880149
2 changed files with 15 additions and 14 deletions

View File

@ -49,12 +49,10 @@ func DeleteAllContainersByLabel(ociBin string, label string) []error {
glog.Infof("error listing containers by label %q: %v", label, err)
}
for _, c := range cs {
if c != "" {
cmd := exec.Command(ociBin, "rm", "-f", "-v", c)
if out, err := cmd.CombinedOutput(); err != nil {
glog.Infof("error deleting container %s: output: %s", c, string(out))
deleteErrs = append(deleteErrs, err)
}
cmd := exec.Command(ociBin, "rm", "-f", "-v", c)
if out, err := cmd.CombinedOutput(); err != nil {
glog.Infof("error deleting container %s: output: %s", c, string(out))
deleteErrs = append(deleteErrs, err)
}
}
return deleteErrs
@ -436,7 +434,9 @@ func listContainersByLabel(ociBinary string, label string) ([]string, error) {
outs := strings.Split(strings.Replace(string(stdout), "\r", "", -1), "\n")
var names []string
for _, o := range outs {
names = append(names, strings.TrimSpace(o))
if strings.TrimSpace(o) != "" {
names = append(names, strings.TrimSpace(o))
}
}
return names, err
}

View File

@ -42,12 +42,10 @@ func DeleteAllVolumesByLabel(ociBin string, label string) []error {
glog.Infof("error listing volumes by label %q: %v", label, err)
}
for _, v := range vs {
if v != "" {
cmd := exec.Command(ociBin, "volume", "rm", "--force", v)
if out, err := cmd.CombinedOutput(); err != nil {
glog.Infof("error deleting volume %s: output: %s", v, string(out))
deleteErrs = append(deleteErrs, err)
}
cmd := exec.Command(ociBin, "volume", "rm", "--force", v)
if out, err := cmd.CombinedOutput(); err != nil {
glog.Infof("error deleting volume %s: output: %s", v, string(out))
deleteErrs = append(deleteErrs, err)
}
}
@ -67,7 +65,10 @@ func allVolumesByLabel(ociBin string, label string) ([]string, error) {
outs := strings.Split(strings.Replace(string(stdout), "\r", "", -1), "\n")
var vols []string
for _, o := range outs {
vols = append(vols, strings.TrimSpace(o))
if strings.TrimSpace(o) != "" {
vols = append(vols, strings.TrimSpace(o))
}
}
return vols, err
}