Split the exported SpecsPaths from the platform-specific implementations,
so that documentation can be maintained in a single location.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -26,7 +26,7 @@ type LocalRegistry struct {
|
| 26 | 26 |
|
| 27 | 27 |
func NewLocalRegistry() LocalRegistry {
|
| 28 | 28 |
return LocalRegistry{
|
| 29 |
- SpecsPaths, |
|
| 29 |
+ SpecsPaths: specsPaths, |
|
| 30 | 30 |
} |
| 31 | 31 |
} |
| 32 | 32 |
|
| ... | ... |
@@ -111,6 +111,25 @@ func (l *LocalRegistry) Plugin(name string) (*Plugin, error) {
|
| 111 | 111 |
return nil, errors.Wrapf(ErrNotFound, "could not find plugin %s in v1 plugin registry", name) |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 |
+// SpecsPaths returns paths in which to look for plugins, in order of priority. |
|
| 115 |
+// |
|
| 116 |
+// On Windows: |
|
| 117 |
+// |
|
| 118 |
+// - "%programdata%\docker\plugins" |
|
| 119 |
+// |
|
| 120 |
+// On Unix in non-rootless mode: |
|
| 121 |
+// |
|
| 122 |
+// - "/etc/docker/plugins" |
|
| 123 |
+// - "/usr/lib/docker/plugins" |
|
| 124 |
+// |
|
| 125 |
+// On Unix in rootless-mode: |
|
| 126 |
+// |
|
| 127 |
+// - "$XDG_CONFIG_HOME/docker/plugins" (or "/etc/docker/plugins" if $XDG_CONFIG_HOME is not set) |
|
| 128 |
+// - "$HOME/.local/lib/docker/plugins" (pr "/usr/lib/docker/plugins" if $HOME is set) |
|
| 129 |
+func SpecsPaths() []string {
|
|
| 130 |
+ return specsPaths() |
|
| 131 |
+} |
|
| 132 |
+ |
|
| 114 | 133 |
func readPluginInfo(name, path string) (*Plugin, error) {
|
| 115 | 134 |
content, err := os.ReadFile(path) |
| 116 | 135 |
if err != nil {
|
| ... | ... |
@@ -9,32 +9,23 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
func rootlessConfigPluginsPath() string {
|
| 12 |
- configHome, err := homedir.GetConfigHome() |
|
| 13 |
- if err == nil {
|
|
| 12 |
+ if configHome, err := homedir.GetConfigHome(); err != nil {
|
|
| 14 | 13 |
return filepath.Join(configHome, "docker/plugins") |
| 15 | 14 |
} |
| 16 |
- |
|
| 17 | 15 |
return "/etc/docker/plugins" |
| 18 | 16 |
} |
| 19 | 17 |
|
| 20 | 18 |
func rootlessLibPluginsPath() string {
|
| 21 |
- libHome, err := homedir.GetLibHome() |
|
| 22 |
- if err == nil {
|
|
| 19 |
+ if libHome, err := homedir.GetLibHome(); err == nil {
|
|
| 23 | 20 |
return filepath.Join(libHome, "docker/plugins") |
| 24 | 21 |
} |
| 25 |
- |
|
| 26 | 22 |
return "/usr/lib/docker/plugins" |
| 27 | 23 |
} |
| 28 | 24 |
|
| 29 |
-// SpecsPaths returns |
|
| 30 |
-// { "%programdata%\docker\plugins" } on Windows,
|
|
| 31 |
-// { "/etc/docker/plugins", "/usr/lib/docker/plugins" } on Unix in non-rootless mode,
|
|
| 32 |
-// { "$XDG_CONFIG_HOME/docker/plugins", "$HOME/.local/lib/docker/plugins" } on Unix in rootless mode
|
|
| 33 |
-// with fallback to the corresponding path in non-rootless mode if $XDG_CONFIG_HOME or $HOME is not set. |
|
| 34 |
-func SpecsPaths() []string {
|
|
| 25 |
+// specsPaths is the non-Windows implementation of [SpecsPaths]. |
|
| 26 |
+func specsPaths() []string {
|
|
| 35 | 27 |
if rootless.RunningWithRootlessKit() {
|
| 36 | 28 |
return []string{rootlessConfigPluginsPath(), rootlessLibPluginsPath()}
|
| 37 | 29 |
} |
| 38 |
- |
|
| 39 | 30 |
return []string{"/etc/docker/plugins", "/usr/lib/docker/plugins"}
|
| 40 | 31 |
} |
| ... | ... |
@@ -5,11 +5,7 @@ import ( |
| 5 | 5 |
"path/filepath" |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 |
-// SpecsPaths returns |
|
| 9 |
-// { "%programdata%\docker\plugins" } on Windows,
|
|
| 10 |
-// { "/etc/docker/plugins", "/usr/lib/docker/plugins" } on Unix in non-rootless mode,
|
|
| 11 |
-// { "$XDG_CONFIG_HOME/docker/plugins", "$HOME/.local/lib/docker/plugins" } on Unix in rootless mode
|
|
| 12 |
-// with fallback to the corresponding path in non-rootless mode if $XDG_CONFIG_HOME or $HOME is not set. |
|
| 13 |
-func SpecsPaths() []string {
|
|
| 8 |
+// specsPaths is the Windows implementation of [SpecsPaths]. |
|
| 9 |
+func specsPaths() []string {
|
|
| 14 | 10 |
return []string{filepath.Join(os.Getenv("programdata"), "docker", "plugins")}
|
| 15 | 11 |
} |