mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client/container_exec.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_exec_test.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_rename.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/pkg/security/security_opts_test.go:8:2: import "gotest.tools/v3/assert/cmp" imported without alias but must be with alias "is" according to config (importas)
"gotest.tools/v3/assert/cmp"
^
client/volume_prune.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/volume_prune_test.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_exec_test.go:10:2: ST1019(related information): other import of "github.com/containerd/errdefs" (staticcheck)
cerrdefs "github.com/containerd/errdefs"
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
cerrdefs "github.com/containerd/errdefs"
|
|
"github.com/moby/moby/api/types/volume"
|
|
)
|
|
|
|
// VolumePruneOptions holds parameters to prune volumes.
|
|
type VolumePruneOptions struct {
|
|
// All controls whether named volumes should also be pruned. By
|
|
// default, only anonymous volumes are pruned.
|
|
All bool
|
|
|
|
// Filters to apply when pruning.
|
|
Filters Filters
|
|
}
|
|
|
|
// VolumePruneResult holds the result from the [Client.VolumePrune] method.
|
|
type VolumePruneResult struct {
|
|
Report volume.PruneReport
|
|
}
|
|
|
|
// VolumePrune requests the daemon to delete unused data
|
|
func (cli *Client) VolumePrune(ctx context.Context, options VolumePruneOptions) (VolumePruneResult, error) {
|
|
if options.All {
|
|
if _, ok := options.Filters["all"]; ok {
|
|
return VolumePruneResult{}, cerrdefs.ErrInvalidArgument.WithMessage(`conflicting options: cannot specify both "all" and "all" filter`)
|
|
}
|
|
if options.Filters == nil {
|
|
options.Filters = Filters{}
|
|
}
|
|
options.Filters.Add("all", "true")
|
|
}
|
|
|
|
query := url.Values{}
|
|
options.Filters.updateURLValues(query)
|
|
|
|
resp, err := cli.post(ctx, "/volumes/prune", query, nil, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return VolumePruneResult{}, err
|
|
}
|
|
|
|
var report volume.PruneReport
|
|
if err := json.NewDecoder(resp.Body).Decode(&report); err != nil {
|
|
return VolumePruneResult{}, fmt.Errorf("error retrieving volume prune report: %v", err)
|
|
}
|
|
|
|
return VolumePruneResult{Report: report}, nil
|
|
}
|