mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
fix(QF1001): Apply De Morgan’s law
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
7d8df25d16
commit
b0711d5fe9
@@ -16,8 +16,12 @@ import (
|
||||
|
||||
// BoolValue transforms a form value in different formats into a boolean type.
|
||||
func BoolValue(r *http.Request, k string) bool {
|
||||
s := strings.ToLower(strings.TrimSpace(r.FormValue(k)))
|
||||
return !(s == "" || s == "0" || s == "no" || s == "false" || s == "none")
|
||||
switch strings.ToLower(strings.TrimSpace(r.FormValue(k))) {
|
||||
case "", "0", "no", "false", "none":
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// BoolValueOrDefault returns the default bool passed if the query param is
|
||||
|
||||
@@ -163,7 +163,7 @@ func (c *containerRouter) getContainersLogs(ctx context.Context, w http.Response
|
||||
// any error after the stream starts (i.e. container not found, wrong parameters)
|
||||
// with the appropriate status code.
|
||||
stdout, stderr := httputils.BoolValue(r, "stdout"), httputils.BoolValue(r, "stderr")
|
||||
if !(stdout || stderr) {
|
||||
if !stdout && !stderr {
|
||||
return errdefs.InvalidParameter(errors.New("Bad parameters: you must choose at least one stream"))
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ func (sr *swarmRouter) swarmLogs(ctx context.Context, w http.ResponseWriter, r *
|
||||
// any error after the stream starts (i.e. container not found, wrong parameters)
|
||||
// with the appropriate status code.
|
||||
stdout, stderr := httputils.BoolValue(r, "stdout"), httputils.BoolValue(r, "stderr")
|
||||
if !(stdout || stderr) {
|
||||
if !stdout && !stderr {
|
||||
return fmt.Errorf("Bad parameters: you must choose at least one stream")
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ func (n NetworkMode) IsDefault() bool {
|
||||
|
||||
// IsPrivate indicates whether container uses its private network stack.
|
||||
func (n NetworkMode) IsPrivate() bool {
|
||||
return !(n.IsHost() || n.IsContainer())
|
||||
return !n.IsHost() && !n.IsContainer()
|
||||
}
|
||||
|
||||
// IsContainer indicates whether container uses a container network stack.
|
||||
@@ -230,7 +230,7 @@ type PidMode string
|
||||
|
||||
// IsPrivate indicates whether the container uses its own new pid namespace.
|
||||
func (n PidMode) IsPrivate() bool {
|
||||
return !(n.IsHost() || n.IsContainer())
|
||||
return !n.IsHost() && !n.IsContainer()
|
||||
}
|
||||
|
||||
// IsHost indicates whether the container uses the host's pid namespace.
|
||||
|
||||
@@ -30,7 +30,7 @@ func GetTimestamp(value string, reference time.Time) (string, error) {
|
||||
|
||||
var format string
|
||||
// if the string has a Z or a + or three dashes use parse otherwise use parseinlocation
|
||||
parseInLocation := !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3)
|
||||
parseInLocation := !strings.ContainsAny(value, "zZ+") && strings.Count(value, "-") != 3
|
||||
|
||||
if strings.Contains(value, ".") {
|
||||
if parseInLocation {
|
||||
|
||||
@@ -216,14 +216,15 @@ func TestCheckoutGit(t *testing.T) {
|
||||
server := httptest.NewServer(&githttp)
|
||||
defer server.Close()
|
||||
|
||||
autocrlf := gitGetConfig("core.autocrlf")
|
||||
if !(autocrlf == "true" || autocrlf == "false" ||
|
||||
autocrlf == "input" || autocrlf == "") {
|
||||
t.Logf("unknown core.autocrlf value: \"%s\"", autocrlf)
|
||||
}
|
||||
eol := "\n"
|
||||
if autocrlf == "true" {
|
||||
autocrlf := gitGetConfig("core.autocrlf")
|
||||
switch autocrlf {
|
||||
case "true":
|
||||
eol = "\r\n"
|
||||
case "false", "input", "":
|
||||
// accepted values
|
||||
default:
|
||||
t.Logf(`unknown core.autocrlf value: "%s"`, autocrlf)
|
||||
}
|
||||
|
||||
must := func(out []byte, err error) {
|
||||
|
||||
@@ -382,7 +382,7 @@ func (r *controller) Shutdown(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err := r.adapter.shutdown(ctx); err != nil {
|
||||
if !(errdefs.IsNotFound(err) || errdefs.IsNotModified(err)) {
|
||||
if !errdefs.IsNotFound(err) && !errdefs.IsNotModified(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, daemonCfg *configStore, hos
|
||||
}
|
||||
|
||||
// ip-forwarding does not affect container with '--net=host' (or '--net=none')
|
||||
if sysInfo.IPv4ForwardingDisabled && !(hostConfig.NetworkMode.IsHost() || hostConfig.NetworkMode.IsNone()) {
|
||||
if sysInfo.IPv4ForwardingDisabled && (!hostConfig.NetworkMode.IsHost() && !hostConfig.NetworkMode.IsNone()) {
|
||||
warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.")
|
||||
}
|
||||
if hostConfig.NetworkMode.IsHost() && len(hostConfig.PortBindings) > 0 {
|
||||
|
||||
@@ -412,5 +412,5 @@ func (i *ImageService) checkImageDeleteConflict(imgID image.ID, mask conflictTyp
|
||||
// that there are no repository references to the given image and it has no
|
||||
// child images.
|
||||
func (i *ImageService) imageIsDangling(imgID image.ID) bool {
|
||||
return !(len(i.referenceStore.References(imgID.Digest())) > 0 || len(i.imageStore.Children(imgID)) > 0)
|
||||
return len(i.referenceStore.References(imgID.Digest())) == 0 && len(i.imageStore.Children(imgID)) == 0
|
||||
}
|
||||
|
||||
@@ -87,10 +87,11 @@ func sanitizeKeyMod(s string) string {
|
||||
} else if ('Z' < v || v < 'A') && ('9' < v || v < '0') {
|
||||
v = '_'
|
||||
}
|
||||
// If (n == "" && v == '_'), then we will skip as this is the beginning with '_'
|
||||
if !(n == "" && v == '_') {
|
||||
n += string(v)
|
||||
if n == "" && v == '_' {
|
||||
// skip leading underscores
|
||||
continue
|
||||
}
|
||||
n += string(v)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
"container": containerName,
|
||||
})
|
||||
|
||||
if !(config.ShowStdout || config.ShowStderr) {
|
||||
if !config.ShowStdout && !config.ShowStderr {
|
||||
return nil, false, errdefs.InvalidParameter(errors.New("You must choose at least one stream"))
|
||||
}
|
||||
ctr, err := daemon.GetContainer(containerName)
|
||||
|
||||
@@ -400,7 +400,7 @@ func (pd *pushDescriptor) Upload(ctx context.Context, progressOutput progress.Ou
|
||||
// when error is unauthorizedError and user don't hasAuthInfo that's the case user don't has right to push layer to register
|
||||
// and he hasn't login either, in this case candidate cache should be removed
|
||||
if len(mountCandidate.SourceRepository) > 0 &&
|
||||
!(isUnauthorizedError && !pd.pushState.hasAuthInfo) &&
|
||||
(!isUnauthorizedError || pd.pushState.hasAuthInfo) &&
|
||||
(metadata.CheckV2MetadataHMAC(&mountCandidate, pd.hmacKey) ||
|
||||
len(mountCandidate.HMAC) == 0) {
|
||||
cause := "blob mount failure"
|
||||
|
||||
@@ -1687,7 +1687,7 @@ func (s *DockerCLIRunSuite) TestRunCopyVolumeContent(c *testing.T) {
|
||||
|
||||
// Test that the content is copied from the image to the volume
|
||||
out := cli.DockerCmd(c, "run", "--rm", "-v", "/hello", name, "find", "/hello").Combined()
|
||||
if !(strings.Contains(out, "/hello/local/world") && strings.Contains(out, "/hello/local")) {
|
||||
if !strings.Contains(out, "/hello/local/world") || !strings.Contains(out, "/hello/local") {
|
||||
c.Fatal("Container failed to transfer content to volume")
|
||||
}
|
||||
}
|
||||
@@ -1726,7 +1726,7 @@ func (s *DockerCLIRunSuite) TestRunWorkdirExistsAndIsFile(c *testing.T) {
|
||||
}
|
||||
|
||||
out, exitCode, err := dockerCmdWithError("run", "-w", existingFile, "busybox")
|
||||
if !(err != nil && exitCode == 125 && strings.Contains(out, expected)) {
|
||||
if err == nil || exitCode != 125 || !strings.Contains(out, expected) {
|
||||
c.Fatalf("Existing binary as a directory should error out with exitCode 125; we got: %s, exitCode: %d", out, exitCode)
|
||||
}
|
||||
}
|
||||
@@ -2904,8 +2904,7 @@ func (s *DockerCLIRunSuite) TestRunUnshareProc(c *testing.T) {
|
||||
name := "acidburn"
|
||||
out, _, err := dockerCmdWithError("run", "--name", name, "--security-opt", "seccomp=unconfined", "debian:bookworm-slim", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount")
|
||||
if err == nil ||
|
||||
!(strings.Contains(strings.ToLower(out), "permission denied") ||
|
||||
strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
(!strings.Contains(strings.ToLower(out), "permission denied") && !strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
errChan <- fmt.Errorf("unshare with --mount-proc should have failed with 'permission denied' or 'operation not permitted', got: %s, %v", out, err)
|
||||
} else {
|
||||
errChan <- nil
|
||||
@@ -2916,9 +2915,7 @@ func (s *DockerCLIRunSuite) TestRunUnshareProc(c *testing.T) {
|
||||
name := "cereal"
|
||||
out, _, err := dockerCmdWithError("run", "--name", name, "--security-opt", "seccomp=unconfined", "debian:bookworm-slim", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc")
|
||||
if err == nil ||
|
||||
!(strings.Contains(strings.ToLower(out), "mount: cannot mount none") ||
|
||||
strings.Contains(strings.ToLower(out), "permission denied") ||
|
||||
strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
(!strings.Contains(strings.ToLower(out), "mount: cannot mount none") && !strings.Contains(strings.ToLower(out), "permission denied") && !strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
errChan <- fmt.Errorf("unshare and mount of /proc should have failed with 'mount: cannot mount none' or 'permission denied', got: %s, %v", out, err)
|
||||
} else {
|
||||
errChan <- nil
|
||||
@@ -2930,9 +2927,7 @@ func (s *DockerCLIRunSuite) TestRunUnshareProc(c *testing.T) {
|
||||
name := "crashoverride"
|
||||
out, _, err := dockerCmdWithError("run", "--privileged", "--security-opt", "seccomp=unconfined", "--security-opt", "apparmor=docker-default", "--name", name, "debian:bookworm-slim", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc")
|
||||
if err == nil ||
|
||||
!(strings.Contains(strings.ToLower(out), "mount: cannot mount none") ||
|
||||
strings.Contains(strings.ToLower(out), "permission denied") ||
|
||||
strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
(!strings.Contains(strings.ToLower(out), "mount: cannot mount none") && !strings.Contains(strings.ToLower(out), "permission denied") && !strings.Contains(strings.ToLower(out), "operation not permitted")) {
|
||||
errChan <- fmt.Errorf("privileged unshare with apparmor should have failed with 'mount: cannot mount none' or 'permission denied', got: %s, %v", out, err)
|
||||
} else {
|
||||
errChan <- nil
|
||||
@@ -3612,7 +3607,7 @@ func (s *DockerCLIRunSuite) TestRunWrongCpusetCpusFlagValue(c *testing.T) {
|
||||
out, exitCode, err := dockerCmdWithError("run", "--cpuset-cpus", "1-10,11--", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
expected := "Error response from daemon: Invalid value 1-10,11-- for cpuset cpus.\n"
|
||||
if !(strings.Contains(out, expected) || exitCode == 125) {
|
||||
if !strings.Contains(out, expected) && exitCode != 125 {
|
||||
c.Fatalf("Expected output to contain %q with exitCode 125, got out: %q exitCode: %v", expected, out, exitCode)
|
||||
}
|
||||
}
|
||||
@@ -3623,7 +3618,7 @@ func (s *DockerCLIRunSuite) TestRunWrongCpusetMemsFlagValue(c *testing.T) {
|
||||
out, exitCode, err := dockerCmdWithError("run", "--cpuset-mems", "1-42--", "busybox", "true")
|
||||
assert.ErrorContains(c, err, "")
|
||||
expected := "Error response from daemon: Invalid value 1-42-- for cpuset mems.\n"
|
||||
if !(strings.Contains(out, expected) || exitCode == 125) {
|
||||
if !strings.Contains(out, expected) && exitCode != 125 {
|
||||
c.Fatalf("Expected output to contain %q with exitCode 125, got out: %q exitCode: %v", expected, out, exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1303,13 +1303,13 @@ func (s *DockerCLIRunSuite) TestRunApparmorProcDirectory(c *testing.T) {
|
||||
// running w seccomp unconfined tests the apparmor profile
|
||||
result := icmd.RunCommand(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/cgroup")
|
||||
result.Assert(c, icmd.Expected{ExitCode: 1})
|
||||
if !(strings.Contains(result.Combined(), "Permission denied") || strings.Contains(result.Combined(), "Operation not permitted")) {
|
||||
if !strings.Contains(result.Combined(), "Permission denied") && !strings.Contains(result.Combined(), "Operation not permitted") {
|
||||
c.Fatalf("expected chmod 777 /proc/1/cgroup to fail, got %s: %v", result.Combined(), result.Error)
|
||||
}
|
||||
|
||||
result = icmd.RunCommand(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/attr/current")
|
||||
result.Assert(c, icmd.Expected{ExitCode: 1})
|
||||
if !(strings.Contains(result.Combined(), "Permission denied") || strings.Contains(result.Combined(), "Operation not permitted")) {
|
||||
if !strings.Contains(result.Combined(), "Permission denied") && !strings.Contains(result.Combined(), "Operation not permitted") {
|
||||
c.Fatalf("expected chmod 777 /proc/1/attr/current to fail, got %s: %v", result.Combined(), result.Error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (s *DockerCLIStartSuite) TestStartMultipleContainers(c *testing.T) {
|
||||
// err shouldn't be nil because start will fail
|
||||
assert.Assert(c, err != nil, "out: %s", out)
|
||||
// output does not correspond to what was expected
|
||||
if !(strings.Contains(out, expOut) || strings.Contains(err.Error(), expErr)) {
|
||||
if !strings.Contains(out, expOut) && !strings.Contains(err.Error(), expErr) {
|
||||
c.Fatalf("Expected out: %v with err: %v but got out: %v with err: %v", expOut, expErr, out, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestRemoveImageGarbageCollector(t *testing.T) {
|
||||
assert.Equal(t, "errno 0", errno.Error())
|
||||
assert.Assert(t, err != nil)
|
||||
errStr := err.Error()
|
||||
if !(strings.Contains(errStr, "permission denied") || strings.Contains(errStr, "operation not permitted")) {
|
||||
if !strings.Contains(errStr, "permission denied") && !strings.Contains(errStr, "operation not permitted") {
|
||||
t.Errorf("ImageRemove error not an permission error %s", errStr)
|
||||
}
|
||||
|
||||
|
||||
@@ -502,7 +502,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
|
||||
if d.init {
|
||||
d.args = append(d.args, "--init")
|
||||
}
|
||||
if !(d.UseDefaultHost || d.UseDefaultTLSHost) {
|
||||
if !d.UseDefaultHost && !d.UseDefaultTLSHost {
|
||||
d.args = append(d.args, "--host", d.Sock())
|
||||
}
|
||||
if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
|
||||
|
||||
@@ -195,7 +195,7 @@ func readFrozenImageList(ctx context.Context, dockerfilePath string, images []st
|
||||
if len(line) < 3 {
|
||||
continue
|
||||
}
|
||||
if !(line[0] == "RUN" && line[1] == "./contrib/download-frozen-image-v2.sh") {
|
||||
if line[0] != "RUN" || line[1] != "./contrib/download-frozen-image-v2.sh" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user