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,14 +49,12 @@ 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)
}
}
}
return deleteErrs
}
@ -436,8 +434,10 @@ 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 {
if strings.TrimSpace(o) != "" {
names = append(names, strings.TrimSpace(o))
}
}
return names, err
}

View File

@ -42,14 +42,12 @@ 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)
}
}
}
// try to prune afterwards just in case delete didn't go through
cmd := exec.Command(ociBin, "volume", "prune", "-f", "--filter", "label="+label)
@ -67,8 +65,11 @@ 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 {
if strings.TrimSpace(o) != "" {
vols = append(vols, strings.TrimSpace(o))
}
}
return vols, err
}