daemon: Remove isWindows const and inline runtime.GOOS check
Other call sites in the package already compare runtime.GOOS directly, so the per-platform const only added inconsistency. runtime.GOOS is a compile-time constant, so dead branches are still eliminated. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
8 files changed
+13
-13
No files matched your search
+2
-1
@@ -3,6 +3,7 @@ package daemon
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/moby/go-archive"
|
||||
@@ -18,7 +19,7 @@ func (daemon *Daemon) ContainerChanges(ctx context.Context, name string) ([]arch
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if isWindows && container.State.IsRunning() {
|
||||
if runtime.GOOS == "windows" && container.State.IsRunning() {
|
||||
return nil, errors.New("Windows does not support diff of a running container")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
|
||||
imageEnvKey, _, _ := strings.Cut(imageEnv, "=")
|
||||
for _, userEnv := range userConf.Env {
|
||||
userEnvKey, _, _ := strings.Cut(userEnv, "=")
|
||||
if isWindows {
|
||||
if runtime.GOOS == "windows" {
|
||||
// Case insensitive environment variables on Windows
|
||||
found = strings.EqualFold(imageEnvKey, userEnvKey)
|
||||
} else {
|
||||
@@ -131,7 +131,7 @@ func (daemon *Daemon) CreateImageFromContainer(ctx context.Context, name string,
|
||||
}
|
||||
|
||||
// It is not possible to commit a running container on Windows
|
||||
if isWindows && container.State.IsRunning() {
|
||||
if runtime.GOOS == "windows" && container.State.IsRunning() {
|
||||
return "", errors.Errorf("%+v does not support commit of a running container", runtime.GOOS)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts
|
||||
}
|
||||
platform = img.Platform()
|
||||
imgID = img.ID()
|
||||
} else if isWindows {
|
||||
} else if runtime.GOOS == "windows" {
|
||||
platform.OS = "linux" // 'scratch' case.
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -886,7 +886,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to get the full path to the TempDir (%s): %s", tmp, err)
|
||||
}
|
||||
if isWindows {
|
||||
if runtime.GOOS == "windows" {
|
||||
if err := os.MkdirAll(realTmp, 0); err != nil {
|
||||
return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err)
|
||||
}
|
||||
@@ -999,7 +999,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if isWindows {
|
||||
if runtime.GOOS == "windows" {
|
||||
// Note that permissions (0o700) are ignored on Windows; passing them to
|
||||
// show intent only. We could consider using idtools.MkdirAndChown here
|
||||
// to apply an ACL.
|
||||
@@ -1064,7 +1064,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
|
||||
shim string
|
||||
shimOpts any
|
||||
)
|
||||
if !isWindows {
|
||||
if runtime.GOOS != "windows" {
|
||||
shim, shimOpts, err = rts.Get("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1631,7 +1631,7 @@ func (daemon *Daemon) Mount(container *container.Container) error {
|
||||
// The mount path reported by the graph driver should always be trusted on Windows, since the
|
||||
// volume path for a given mounted layer may change over time. This should only be an error
|
||||
// on non-Windows operating systems.
|
||||
if !isWindows {
|
||||
if runtime.GOOS != "windows" {
|
||||
daemon.Unmount(container)
|
||||
driver := daemon.ImageService().StorageDriver()
|
||||
return fmt.Errorf("driver %s is returning inconsistent paths for container %s ('%s' then '%s')",
|
||||
|
||||
@@ -52,8 +52,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
isWindows = false
|
||||
|
||||
// These values were used to adjust the CPU-shares for older API versions,
|
||||
// but were not used for validation.
|
||||
//
|
||||
|
||||
@@ -33,7 +33,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
isWindows = true
|
||||
windowsMinCPUShares = 1
|
||||
windowsMaxCPUShares = 10000
|
||||
windowsMinCPUPercent = 1
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
|
||||
"github.com/containerd/log"
|
||||
"github.com/moby/go-archive"
|
||||
@@ -23,7 +24,7 @@ func (daemon *Daemon) ContainerExport(ctx context.Context, name string, out io.W
|
||||
return err
|
||||
}
|
||||
|
||||
if isWindows && ctr.ImagePlatform.OS == "windows" {
|
||||
if runtime.GOOS == "windows" && ctr.ImagePlatform.OS == "windows" {
|
||||
return errors.New("the daemon on this operating system does not support exporting Windows containers")
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -189,7 +190,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
|
||||
switch e {
|
||||
case libcontainerdtypes.EventOOM:
|
||||
// StateOOM is Linux specific and should never be hit on Windows
|
||||
if isWindows {
|
||||
if runtime.GOOS == "windows" {
|
||||
return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user