@@ -60,6 +60,46 @@ func (d *DefaultsProvider) home() string {
6060 return home
6161}
6262
63+ // config returns the user's config dir.
64+ func (d * DefaultsProvider ) config () string {
65+ home , err := os .UserHomeDir ()
66+ if err != nil {
67+ logrus .Fatalf ("unable to get user home dir: %s" , err )
68+ }
69+
70+ // use the XDG_CONFIG_HOME environment variable if set
71+ if xdgConfigHome := os .Getenv ("XDG_CONFIG_HOME" ); xdgConfigHome != "" {
72+ return xdgConfigHome
73+ }
74+
75+ // otherwise, default to $HOME/.config on linux
76+ if runtime .GOOS == "linux" {
77+ return filepath .Join (home , ".config" )
78+ }
79+
80+ return home
81+ }
82+
83+ // state returns the user's state dir.
84+ func (d * DefaultsProvider ) state () string {
85+ home , err := os .UserHomeDir ()
86+ if err != nil {
87+ logrus .Fatalf ("unable to get user home dir: %s" , err )
88+ }
89+
90+ // use the XDG_STATE_HOME environment variable if set
91+ if xdgStateHome := os .Getenv ("XDG_STATE_HOME" ); xdgStateHome != "" {
92+ return xdgStateHome
93+ }
94+
95+ // otherwise, default to $HOME/.local/state on linux
96+ if runtime .GOOS == "linux" {
97+ return filepath .Join (home , ".local" , "state" )
98+ }
99+
100+ return home
101+ }
102+
63103// BinaryName returns the binary name, this is useful for places where we
64104// need to present the name of the binary to the user (the name may vary if
65105// the binary is renamed). We make sure the name does not contain invalid
@@ -77,7 +117,7 @@ func (d *DefaultsProvider) BinaryName() string {
77117// stored. This is a subdirectory of the user's home directory.
78118func (d * DefaultsProvider ) HelmVMLogsSubDir () string {
79119 hidden := fmt .Sprintf (".%s" , d .BinaryName ())
80- return filepath .Join (d .Base , d .home (), hidden , "logs" )
120+ return filepath .Join (d .Base , d .state (), hidden , "logs" )
81121}
82122
83123// PathToLog returns the full path to a log file. This function does not check
@@ -100,7 +140,7 @@ func (d *DefaultsProvider) K0sctlBinsSubDir() string {
100140// are stored. This is a subdirectory of the user's home directory.
101141func (d * DefaultsProvider ) HelmVMBinsSubDir () string {
102142 hidden := fmt .Sprintf (".%s" , d .BinaryName ())
103- return filepath .Join (d .Base , d .home (), hidden , "bin" )
143+ return filepath .Join (d .Base , d .config (), hidden , "bin" )
104144}
105145
106146// K0sctlApplyLogPath returns the path to the k0sctl apply log file.
@@ -126,9 +166,10 @@ func (d *DefaultsProvider) SSHConfigSubDir() string {
126166
127167// ConfigSubDir returns the path to the directory where k0sctl configuration
128168// files are stored. This is a subdirectory of the user's home directory.
169+ // TODO update
129170func (d * DefaultsProvider ) ConfigSubDir () string {
130171 hidden := fmt .Sprintf (".%s" , d .BinaryName ())
131- return filepath .Join (d .Base , d .home (), hidden , "etc" )
172+ return filepath .Join (d .Base , d .config (), hidden , "etc" )
132173}
133174
134175// K0sBinaryPath returns the path to the k0s binary.
0 commit comments