From 7710e898ea5a52ef67bafa5b4a54581985c523be Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Wed, 17 May 2023 17:03:14 +0200 Subject: [PATCH] fix: Invert the API version error check (#78) * fix: Negate API version err check * chore: Log all filters --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 32e23e0..baa624d 100644 --- a/main.go +++ b/main.go @@ -322,13 +322,13 @@ func prune(cli *client.Client, deathNote *sync.Map) (deletedContainers int, dele _ = try.Do(func(attempt int) (bool, error) { argsClone := args.Clone() - if verbose { - log.Printf("Deleting volumes with filter: %#v. (Attempt %d/%d)\n", argsClone, attempt, 10) + // The API version >= v1.42 prunes only anonymous volumes: https://github.com/moby/moby/releases/tag/v23.0.0. + if serverVersion, err := cli.ServerVersion(context.Background()); err == nil && serverVersion.APIVersion >= "1.42" { + argsClone.Add("all", "true") } - // API version >= v1.42 prunes only anonymous volumes: https://github.com/moby/moby/releases/tag/v23.0.0. - if serverVersion, err := cli.ServerVersion(context.Background()); err != nil && serverVersion.APIVersion >= "1.42" { - argsClone.Add("all", "true") + if verbose { + log.Printf("Deleting volumes with filter: %#v. (Attempt %d/%d)\n", argsClone, attempt, 10) } volumesPruneReport, err := cli.VolumesPrune(context.Background(), argsClone)