DockerCLI/cli/config
Sebastiaan van Stijn 13e842a110
cli/config: add synchronisation for configDir (Dir, SetDir)
commit 8a30653ed5 introduced a sync.Once
to allow for the config-directory (and home-dir) to be looked up lazily
instead of in an `init()`.

However, the package-level `configDir` variable can be set through two
separate paths; implicitly (through `config.Dir()`), and explicitly,
through `config.SetDir()`. The existing code had no synchronisation for
this, which could lead to a potential race-condition (code requesting
`config.Dir()` and code setting a custom path through `config.SetDir()`).

This patch adds synchronisation by triggering the `sync.Once` as part of
`config.SetDir()` to prevent it being triggered later (overwriting the
value that was set). It also restores the `resetConfigDir()` utility that
was removed in 379122b033, to allow resetting
the `sync.Once` for this test.

In general, we should get rid of this package-level variable, and store
it as a config on the client (passing the option to locations where its
used instead).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-28 12:58:26 +02:00
..
configfile remove pre-go1.17 build-tags 2023-05-05 18:23:03 +02:00
credentials remove uses of golang.org/x/sys/execabs 2023-05-26 02:03:45 +02:00
types Remove docker api dependency from cli/config 2019-01-31 21:25:43 +00:00
config.go cli/config: add synchronisation for configDir (Dir, SetDir) 2023-06-28 12:58:26 +02:00
config_test.go cli/config: add synchronisation for configDir (Dir, SetDir) 2023-06-28 12:58:26 +02:00