summaryrefslogtreecommitdiff
path: root/pkg/plugins/discovery_unix.go
blob: 2c1b2a31933afb7329a0d35e8920fd2ff419c68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//go:build !windows
// +build !windows

package plugins // import "github.com/docker/docker/pkg/plugins"
import (
	"path/filepath"

	"github.com/docker/docker/pkg/homedir"
	"github.com/docker/docker/pkg/rootless"
)

func rootlessConfigPluginsPath() string {
	configHome, err := homedir.GetConfigHome()
	if err == nil {
		return filepath.Join(configHome, "docker/plugins")
	}

	return "/etc/docker/plugins"
}

func rootlessLibPluginsPath() string {
	libHome, err := homedir.GetLibHome()
	if err == nil {
		return filepath.Join(libHome, "docker/plugins")
	}

	return "/usr/lib/docker/plugins"
}

// SpecsPaths returns
// { "%programdata%\docker\plugins" } on Windows,
// { "/etc/docker/plugins", "/usr/lib/docker/plugins" } on Unix in non-rootless mode,
// { "$XDG_CONFIG_HOME/docker/plugins", "$HOME/.local/lib/docker/plugins" } on Unix in rootless mode
// with fallback to the corresponding path in non-rootless mode if $XDG_CONFIG_HOME or $HOME is not set.
func SpecsPaths() []string {
	if rootless.RunningWithRootlessKit() {
		return []string{rootlessConfigPluginsPath(), rootlessLibPluginsPath()}
	}

	return []string{"/etc/docker/plugins", "/usr/lib/docker/plugins"}
}