4
4
"context"
5
5
"sort"
6
6
7
+ "github.com/docker/docker/api/types"
7
8
"github.com/docker/docker/api/types/filters"
9
+ "github.com/docker/docker/api/types/mount"
8
10
"github.com/docker/docker/api/types/volume"
9
11
"github.com/docker/docker/client"
10
12
)
@@ -15,16 +17,32 @@ func VolumeList(req *DockerVolumeList) (*DockerVolumeListResponse, error) {
15
17
return nil , err
16
18
}
17
19
20
+ dcontainers , err := cli .ContainerList (context .Background (), types.ContainerListOptions {All : true })
21
+ if err != nil {
22
+ return nil , err
23
+ }
24
+
25
+ usedVolumes := make (map [string ]interface {}, 0 )
26
+ for _ , c := range dcontainers {
27
+ for _ , m := range c .Mounts {
28
+ if m .Type == mount .TypeVolume {
29
+ usedVolumes [m .Name ] = nil
30
+ }
31
+ }
32
+ }
33
+
18
34
dvolumes , err := cli .VolumeList (context .Background (), volume.ListOptions {})
19
35
if err != nil {
20
36
return nil , err
21
37
}
22
38
23
39
volumes := make ([]Volume , len (dvolumes .Volumes ))
24
40
for i , item := range dvolumes .Volumes {
41
+ _ , isUse := usedVolumes [item .Name ]
25
42
volumes [i ] = Volume {
26
43
Driver : item .Driver ,
27
44
Name : item .Name ,
45
+ InUse : isUse ,
28
46
}
29
47
}
30
48
@@ -56,7 +74,7 @@ func VolumesPrune(req *DockerVolumesPrune) (*DockerVolumesPruneResponse, error)
56
74
}
57
75
58
76
all := "true"
59
- if req .All {
77
+ if ! req .All {
60
78
all = "false"
61
79
}
62
80
allFilter := filters.KeyValuePair {Key : "all" , Value : all }
0 commit comments