diff --git a/daemon/checkpoint.go b/daemon/checkpoint.go index 97acc1d897..9da1cc3ee9 100644 --- a/daemon/checkpoint.go +++ b/daemon/checkpoint.go @@ -31,7 +31,7 @@ func getCheckpointDir(checkDir, checkpointID, ctrName, ctrID, ctrCheckpointDir s case err == nil && stat.IsDir(): err2 = fmt.Errorf("checkpoint with name %s already exists for container %s", checkpointID, ctrName) case err != nil && os.IsNotExist(err): - err2 = os.MkdirAll(checkpointAbsDir, 0700) + err2 = os.MkdirAll(checkpointAbsDir, 0o700) case err != nil: err2 = err default: @@ -111,7 +111,7 @@ func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOpt return nil, err } - if err := os.MkdirAll(checkpointDir, 0755); err != nil { + if err := os.MkdirAll(checkpointDir, 0o755); err != nil { return nil, err } diff --git a/daemon/container_operations.go b/daemon/container_operations.go index 8ea7df60a3..54aa445d03 100644 --- a/daemon/container_operations.go +++ b/daemon/container_operations.go @@ -685,7 +685,6 @@ func cleanOperationalData(es *network.EndpointSettings) { } func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error { - if containertypes.NetworkMode(n.Name()).IsUserDefined() { addShortID := true shortID := stringid.TruncateID(container.ID) diff --git a/daemon/container_operations_unix.go b/daemon/container_operations_unix.go index 2db1f7188b..2277889ab9 100644 --- a/daemon/container_operations_unix.go +++ b/daemon/container_operations_unix.go @@ -141,7 +141,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error { return err } - if err := idtools.MkdirAllAndChown(shmPath, 0700, rootIDs); err != nil { + if err := idtools.MkdirAllAndChown(shmPath, 0o700, rootIDs); err != nil { return err } @@ -196,7 +196,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) { if err != nil { return errors.Wrap(err, "error getting secret file path") } - if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0700, rootIDs); err != nil { + if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0o700, rootIDs); err != nil { return errors.Wrap(err, "error creating secret mount path") } @@ -247,7 +247,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) { if err != nil { return errors.Wrap(err, "error getting config file path for container") } - if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0700, rootIDs); err != nil { + if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0o700, rootIDs); err != nil { return errors.Wrap(err, "error creating config mount path") } @@ -294,7 +294,7 @@ func (daemon *Daemon) createSecretsDir(c *container.Container) error { } // create tmpfs - if err := idtools.MkdirAllAndChown(dir, 0700, rootIDs); err != nil { + if err := idtools.MkdirAllAndChown(dir, 0o700, rootIDs); err != nil { return errors.Wrap(err, "error creating secret local mount path") } @@ -461,5 +461,5 @@ func (daemon *Daemon) setupContainerMountsRoot(c *container.Container) error { if err != nil { return err } - return idtools.MkdirAllAndChown(p, 0710, idtools.Identity{UID: idtools.CurrentIdentity().UID, GID: daemon.IdentityMapping().RootPair().GID}) + return idtools.MkdirAllAndChown(p, 0o710, idtools.Identity{UID: idtools.CurrentIdentity().UID, GID: daemon.IdentityMapping().RootPair().GID}) } diff --git a/daemon/container_operations_windows.go b/daemon/container_operations_windows.go index f122038ed8..9dc5461847 100644 --- a/daemon/container_operations_windows.go +++ b/daemon/container_operations_windows.go @@ -169,7 +169,6 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container } func (daemon *Daemon) initializeNetworkingPaths(container *container.Container, nc *container.Container) error { - if nc.HostConfig.Isolation.IsHyperV() { return fmt.Errorf("sharing of hyperv containers network is not supported") } diff --git a/daemon/content.go b/daemon/content.go index 3ac69db743..a97ad20d7b 100644 --- a/daemon/content.go +++ b/daemon/content.go @@ -17,10 +17,10 @@ import ( ) func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leases.Manager, error) { - if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0700); err != nil { + if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0o700); err != nil { return nil, nil, errors.Wrap(err, "error creating dir for content store") } - db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0600, nil) + db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0o600, nil) if err != nil { return nil, nil, errors.Wrap(err, "error opening bolt db for content metadata store") } diff --git a/daemon/create.go b/daemon/create.go index 153e7e2511..2ca004ab11 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -197,10 +197,10 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts } current := idtools.CurrentIdentity() - if err := idtools.MkdirAndChown(ctr.Root, 0710, idtools.Identity{UID: current.UID, GID: daemon.IdentityMapping().RootPair().GID}); err != nil { + if err := idtools.MkdirAndChown(ctr.Root, 0o710, idtools.Identity{UID: current.UID, GID: daemon.IdentityMapping().RootPair().GID}); err != nil { return nil, err } - if err := idtools.MkdirAndChown(ctr.CheckpointDir(), 0700, current); err != nil { + if err := idtools.MkdirAndChown(ctr.CheckpointDir(), 0o700, current); err != nil { return nil, err } diff --git a/daemon/daemon_linux_test.go b/daemon/daemon_linux_test.go index 5bc24f45a7..4e304b8037 100644 --- a/daemon/daemon_linux_test.go +++ b/daemon/daemon_linux_test.go @@ -258,9 +258,9 @@ func TestRootMountCleanup(t *testing.T) { cfg.ExecRoot = filepath.Join(testRoot, "exec") cfg.Root = filepath.Join(testRoot, "daemon") - err = os.Mkdir(cfg.ExecRoot, 0755) + err = os.Mkdir(cfg.ExecRoot, 0o755) assert.NilError(t, err) - err = os.Mkdir(cfg.Root, 0755) + err = os.Mkdir(cfg.Root, 0o755) assert.NilError(t, err) d := &Daemon{root: cfg.Root} @@ -319,7 +319,7 @@ func TestRootMountCleanup(t *testing.T) { err = mount.MakeShared(testRoot) assert.NilError(t, err) defer mount.MakePrivate(testRoot) - err = os.WriteFile(unmountFile, nil, 0644) + err = os.WriteFile(unmountFile, nil, 0o644) assert.NilError(t, err) err = setupDaemonRootPropagation(&cfg.Config) diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index ced1ecfab9..85afcc41cc 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -150,7 +150,7 @@ func TestContainerInitDNS(t *testing.T) { containerID := "d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e" containerPath := filepath.Join(tmp, containerID) - if err := os.MkdirAll(containerPath, 0755); err != nil { + if err := os.MkdirAll(containerPath, 0o755); err != nil { t.Fatal(err) } @@ -176,7 +176,7 @@ func TestContainerInitDNS(t *testing.T) { if err != nil { t.Fatal(err) } - if err = os.WriteFile(configPath, []byte(config), 0644); err != nil { + if err = os.WriteFile(configPath, []byte(config), 0o644); err != nil { t.Fatal(err) } @@ -189,7 +189,7 @@ func TestContainerInitDNS(t *testing.T) { if err != nil { t.Fatal(err) } - if err = os.WriteFile(hostConfigPath, []byte(hostConfig), 0644); err != nil { + if err = os.WriteFile(hostConfigPath, []byte(hostConfig), 0o644); err != nil { t.Fatal(err) } diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 113f5684f7..7010c9b637 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -1213,19 +1213,19 @@ func setupDaemonRoot(config *config.Config, rootDir string, remappedRoot idtools // layer content subtrees. if _, err := os.Stat(rootDir); err == nil { // root current exists; verify the access bits are correct by setting them - if err = os.Chmod(rootDir, 0711); err != nil { + if err = os.Chmod(rootDir, 0o711); err != nil { return err } } else if os.IsNotExist(err) { // no root exists yet, create it 0711 with root:root ownership - if err := os.MkdirAll(rootDir, 0711); err != nil { + if err := os.MkdirAll(rootDir, 0o711); err != nil { return err } } id := idtools.Identity{UID: idtools.CurrentIdentity().UID, GID: remappedRoot.GID} // First make sure the current root dir has the correct perms. - if err := idtools.MkdirAllAndChown(config.Root, 0710, id); err != nil { + if err := idtools.MkdirAllAndChown(config.Root, 0o710, id); err != nil { return errors.Wrapf(err, "could not create or set daemon root permissions: %s", config.Root) } @@ -1237,7 +1237,7 @@ func setupDaemonRoot(config *config.Config, rootDir string, remappedRoot idtools config.Root = filepath.Join(rootDir, fmt.Sprintf("%d.%d", remappedRoot.UID, remappedRoot.GID)) log.G(context.TODO()).Debugf("Creating user namespaced daemon root: %s", config.Root) // Create the root directory if it doesn't exist - if err := idtools.MkdirAllAndChown(config.Root, 0710, id); err != nil { + if err := idtools.MkdirAllAndChown(config.Root, 0o710, id); err != nil { return fmt.Errorf("Cannot create daemon root: %s: %v", config.Root, err) } // we also need to verify that any pre-existing directories in the path to @@ -1323,11 +1323,11 @@ func setupDaemonRootPropagation(cfg *config.Config) error { return nil } - if err := os.MkdirAll(filepath.Dir(cleanupFile), 0700); err != nil { + if err := os.MkdirAll(filepath.Dir(cleanupFile), 0o700); err != nil { return errors.Wrap(err, "error creating dir to store mount cleanup file") } - if err := os.WriteFile(cleanupFile, nil, 0600); err != nil { + if err := os.WriteFile(cleanupFile, nil, 0o600); err != nil { return errors.Wrap(err, "error writing file to signal mount cleanup on shutdown") } return nil @@ -1446,7 +1446,7 @@ func (daemon *Daemon) initCPURtController(cfg *config.Config, mnt, path string) } path = filepath.Join(mnt, path) - if err := os.MkdirAll(path, 0755); err != nil { + if err := os.MkdirAll(path, 0o755); err != nil { return err } if err := maybeCreateCPURealTimeFile(cfg.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil { @@ -1459,7 +1459,7 @@ func maybeCreateCPURealTimeFile(configValue int64, file string, path string) err if configValue == 0 { return nil } - return os.WriteFile(filepath.Join(path, file), []byte(strconv.FormatInt(configValue, 10)), 0700) + return os.WriteFile(filepath.Join(path, file), []byte(strconv.FormatInt(configValue, 10)), 0o700) } func (daemon *Daemon) setupSeccompProfile(cfg *config.Config) error { diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 5800deac78..87e3339a23 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -10,6 +10,7 @@ import ( "github.com/Microsoft/hcsshim" "github.com/Microsoft/hcsshim/osversion" + "github.com/containerd/containerd/log" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" "github.com/docker/docker/daemon/config" @@ -28,7 +29,6 @@ import ( "github.com/docker/docker/pkg/system" "github.com/docker/docker/runconfig" "github.com/pkg/errors" - "github.com/containerd/containerd/log" "golang.org/x/sys/windows" "golang.org/x/sys/windows/svc/mgr" ) @@ -198,7 +198,7 @@ func checkSystem() error { // Ensure that the required Host Network Service and vmcompute services // are running. Docker will fail in unexpected ways if this is not present. - var requiredServices = []string{"hns", "vmcompute"} + requiredServices := []string{"hns", "vmcompute"} if err := ensureServicesInstalled(requiredServices); err != nil { return errors.Wrap(err, "a required service is not installed, ensure the Containers feature is installed") } @@ -390,7 +390,6 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand }), libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil), ) - if err != nil { log.G(context.TODO()).Errorf("Error occurred when creating network %v", err) } @@ -482,7 +481,6 @@ func (daemon *Daemon) runAsHyperVContainer(hostConfig *containertypes.HostConfig // Container is requesting an isolation mode. Honour it. return hostConfig.Isolation.IsHyperV() - } // conditionalMountOnStart is a platform specific helper function during the diff --git a/daemon/delete.go b/daemon/delete.go index 5a230d13c5..c901de70e3 100644 --- a/daemon/delete.go +++ b/daemon/delete.go @@ -116,7 +116,7 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, config ty // // If you arrived here and know the answer, you earned yourself a picture // of a cute animal of your own choosing. - var stopTimeout = 3 + stopTimeout := 3 if err := daemon.containerStop(context.TODO(), container, containertypes.StopOptions{Timeout: &stopTimeout}); err != nil { return err } diff --git a/daemon/delete_test.go b/daemon/delete_test.go index de7bbdc486..3272792d7f 100644 --- a/daemon/delete_test.go +++ b/daemon/delete_test.go @@ -45,7 +45,8 @@ func TestContainerDelete(t *testing.T) { fixMsg: "Unpause and then stop the container before attempting removal or force remove", initContainer: func() *container.Container { return newContainerWithState(&container.State{Paused: true, Running: true}) - }}, + }, + }, // a restarting container { errMsg: "cannot remove a restarting container", @@ -55,14 +56,16 @@ func TestContainerDelete(t *testing.T) { c.SetRunning(nil, nil, true) c.SetRestarting(&container.ExitStatus{}) return c - }}, + }, + }, // a running container { errMsg: "cannot remove a running container", fixMsg: "Stop the container before attempting removal or force remove", initContainer: func() *container.Container { return newContainerWithState(&container.State{Running: true}) - }}, + }, + }, } for _, te := range tt { diff --git a/daemon/events.go b/daemon/events.go index 684ddff949..8bf73ef548 100644 --- a/daemon/events.go +++ b/daemon/events.go @@ -16,13 +16,11 @@ import ( swarmapi "github.com/moby/swarmkit/v2/api" ) -var ( - clusterEventAction = map[swarmapi.WatchActionKind]string{ - swarmapi.WatchActionKindCreate: "create", - swarmapi.WatchActionKindUpdate: "update", - swarmapi.WatchActionKindRemove: "remove", - } -) +var clusterEventAction = map[swarmapi.WatchActionKind]string{ + swarmapi.WatchActionKindCreate: "create", + swarmapi.WatchActionKindUpdate: "update", + swarmapi.WatchActionKindRemove: "remove", +} // LogContainerEvent generates an event related to a container with only the default attributes. func (daemon *Daemon) LogContainerEvent(container *container.Container, action string) { diff --git a/daemon/id.go b/daemon/id.go index cf520ca156..d684dca357 100644 --- a/daemon/id.go +++ b/daemon/id.go @@ -20,7 +20,7 @@ func loadOrCreateID(idPath string) (string, error) { idb, err := os.ReadFile(idPath) if os.IsNotExist(err) { id = uuid.New().String() - if err := ioutils.AtomicWriteFile(idPath, []byte(id), os.FileMode(0600)); err != nil { + if err := ioutils.AtomicWriteFile(idPath, []byte(id), os.FileMode(0o600)); err != nil { return "", errors.Wrap(err, "error saving ID file") } } else if err != nil { diff --git a/daemon/initlayer/setup_unix.go b/daemon/initlayer/setup_unix.go index 4d2c84cafb..51621e4eb7 100644 --- a/daemon/initlayer/setup_unix.go +++ b/daemon/initlayer/setup_unix.go @@ -42,16 +42,16 @@ func Setup(initLayerFs string, rootIdentity idtools.Identity) error { if _, err := os.Stat(filepath.Join(initLayer, pth)); err != nil { if os.IsNotExist(err) { - if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, filepath.Dir(pth)), 0755, rootIdentity); err != nil { + if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, filepath.Dir(pth)), 0o755, rootIdentity); err != nil { return err } switch typ { case "dir": - if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, pth), 0755, rootIdentity); err != nil { + if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, pth), 0o755, rootIdentity); err != nil { return err } case "file": - f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0755) + f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0o755) if err != nil { return err } diff --git a/daemon/list.go b/daemon/list.go index 6c86b72905..73681968e2 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -330,7 +330,6 @@ func (daemon *Daemon) foldFilter(ctx context.Context, view *container.View, conf // Then walk down the graph and put the imageIds in imagesFilter return populateImageFilterByParents(ctx, imagesFilter, img.ID(), daemon.imageService.Children) }) - if err != nil { return nil, err } diff --git a/daemon/list_test.go b/daemon/list_test.go index a972845cab..982575bc1e 100644 --- a/daemon/list_test.go +++ b/daemon/list_test.go @@ -40,7 +40,7 @@ func setupContainerWithName(t *testing.T, name string, daemon *Daemon) *containe computedImageID = image.ID(digest.FromString(id)) cRoot = filepath.Join(root, id) ) - if err := os.MkdirAll(cRoot, 0755); err != nil { + if err := os.MkdirAll(cRoot, 0o755); err != nil { t.Fatal(err) } diff --git a/daemon/network.go b/daemon/network.go index f808727644..2370496ba2 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -1076,9 +1076,7 @@ func buildEndpointInfo(networkSettings *internalnetwork.Settings, n libnetwork.N } // buildJoinOptions builds endpoint Join options from a given network. -func buildJoinOptions(networkSettings *internalnetwork.Settings, n interface { - Name() string -}) ([]libnetwork.EndpointOption, error) { +func buildJoinOptions(networkSettings *internalnetwork.Settings, n interface{ Name() string }) ([]libnetwork.EndpointOption, error) { var joinOptions []libnetwork.EndpointOption if epConfig, ok := networkSettings.Networks[n.Name()]; ok { for _, str := range epConfig.Links { diff --git a/daemon/oci_linux_test.go b/daemon/oci_linux_test.go index 787451cbb5..d5ea294318 100644 --- a/daemon/oci_linux_test.go +++ b/daemon/oci_linux_test.go @@ -24,7 +24,7 @@ func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon { root := t.TempDir() rootfs := filepath.Join(root, "rootfs") - err := os.MkdirAll(rootfs, 0755) + err := os.MkdirAll(rootfs, 0o755) assert.NilError(t, err) netController, err := libnetwork.New() diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index 920686b569..2dbbf69c57 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -219,7 +219,6 @@ func (daemon *Daemon) createSpec(ctx context.Context, daemonCfg *configStore, c // Sets the Windows-specific fields of the OCI spec func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.Spec, isHyperV bool) error { - s.Hostname = c.FullHostname() if len(s.Process.Cwd) == 0 { diff --git a/daemon/oci_windows_test.go b/daemon/oci_windows_test.go index 9237ddc12e..4d60289cbe 100644 --- a/daemon/oci_windows_test.go +++ b/daemon/oci_windows_test.go @@ -70,7 +70,7 @@ func TestSetWindowsCredentialSpecInSpec(t *testing.T) { assert.NilError(t, err) dummyCredFileName := "dummy-cred-spec.json" dummyCredFilePath := filepath.Join(credSpecsDir, dummyCredFileName) - err = os.WriteFile(dummyCredFilePath, []byte(dummyCredFileContents), 0644) + err = os.WriteFile(dummyCredFilePath, []byte(dummyCredFileContents), 0o644) defer func() { assert.NilError(t, os.Remove(dummyCredFilePath)) }() diff --git a/daemon/restart.go b/daemon/restart.go index 522160ddb6..f1896a9035 100644 --- a/daemon/restart.go +++ b/daemon/restart.go @@ -55,7 +55,6 @@ func (daemon *Daemon) containerRestart(ctx context.Context, daemonCfg *configSto container.Unlock() err := daemon.containerStop(ctx, container, options) - if err != nil { return err } diff --git a/daemon/top_windows.go b/daemon/top_windows.go index 203a5b7c62..c99adf45d3 100644 --- a/daemon/top_windows.go +++ b/daemon/top_windows.go @@ -64,7 +64,8 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes. j.ImageName, fmt.Sprint(j.ProcessID), fmt.Sprintf("%02d:%02d:%02d.%03d", int(d.Hours()), int(d.Minutes())%60, int(d.Seconds())%60, int(d.Nanoseconds()/1000000)%1000), - units.HumanSize(float64(j.MemoryWorkingSetPrivateBytes))}) + units.HumanSize(float64(j.MemoryWorkingSetPrivateBytes)), + }) } return procList, nil