|
@@ -18,6 +18,8 @@ import (
|
|
|
|
|
|
var acceptedVolumeFilterTags = map[string]bool{
|
|
|
"dangling": true,
|
|
|
+ "name": true,
|
|
|
+ "driver": true,
|
|
|
}
|
|
|
|
|
|
var acceptedPsFilterTags = map[string]bool{
|
|
@@ -472,8 +474,7 @@ func (daemon *Daemon) transformContainer(container *container.Container, ctx *li
|
|
|
// of volumes returned.
|
|
|
func (daemon *Daemon) Volumes(filter string) ([]*types.Volume, []string, error) {
|
|
|
var (
|
|
|
- volumesOut []*types.Volume
|
|
|
- danglingOnly = false
|
|
|
+ volumesOut []*types.Volume
|
|
|
)
|
|
|
volFilters, err := filters.FromParam(filter)
|
|
|
if err != nil {
|
|
@@ -484,27 +485,51 @@ func (daemon *Daemon) Volumes(filter string) ([]*types.Volume, []string, error)
|
|
|
return nil, nil, err
|
|
|
}
|
|
|
|
|
|
- if volFilters.Include("dangling") {
|
|
|
- if volFilters.ExactMatch("dangling", "true") || volFilters.ExactMatch("dangling", "1") {
|
|
|
- danglingOnly = true
|
|
|
- } else if !volFilters.ExactMatch("dangling", "false") && !volFilters.ExactMatch("dangling", "0") {
|
|
|
- return nil, nil, fmt.Errorf("Invalid filter 'dangling=%s'", volFilters.Get("dangling"))
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
volumes, warnings, err := daemon.volumes.List()
|
|
|
+ filterVolumes, err := daemon.filterVolumes(volumes, volFilters)
|
|
|
if err != nil {
|
|
|
return nil, nil, err
|
|
|
}
|
|
|
- if volFilters.Include("dangling") {
|
|
|
- volumes = daemon.volumes.FilterByUsed(volumes, !danglingOnly)
|
|
|
- }
|
|
|
- for _, v := range volumes {
|
|
|
+ for _, v := range filterVolumes {
|
|
|
volumesOut = append(volumesOut, volumeToAPIType(v))
|
|
|
}
|
|
|
return volumesOut, warnings, nil
|
|
|
}
|
|
|
|
|
|
+// filterVolumes filters volume list according to user specified filter
|
|
|
+// and returns user chosen volumes
|
|
|
+func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) ([]volume.Volume, error) {
|
|
|
+ // if filter is empty, return original volume list
|
|
|
+ if filter.Len() == 0 {
|
|
|
+ return vols, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ var retVols []volume.Volume
|
|
|
+ for _, vol := range vols {
|
|
|
+ if filter.Include("name") {
|
|
|
+ if !filter.Match("name", vol.Name()) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if filter.Include("driver") {
|
|
|
+ if !filter.Match("driver", vol.DriverName()) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ retVols = append(retVols, vol)
|
|
|
+ }
|
|
|
+ danglingOnly := false
|
|
|
+ if filter.Include("dangling") {
|
|
|
+ if filter.ExactMatch("dangling", "true") || filter.ExactMatch("dangling", "1") {
|
|
|
+ danglingOnly = true
|
|
|
+ } else if !filter.ExactMatch("dangling", "false") && !filter.ExactMatch("dangling", "0") {
|
|
|
+ return nil, fmt.Errorf("Invalid filter 'dangling=%s'", filter.Get("dangling"))
|
|
|
+ }
|
|
|
+ retVols = daemon.volumes.FilterByUsed(retVols, !danglingOnly)
|
|
|
+ }
|
|
|
+ return retVols, nil
|
|
|
+}
|
|
|
+
|
|
|
func populateImageFilterByParents(ancestorMap map[image.ID]bool, imageID image.ID, getChildren func(image.ID) []image.ID) {
|
|
|
if !ancestorMap[imageID] {
|
|
|
for _, id := range getChildren(imageID) {
|