@@ -12,6 +12,10 @@ flavors of Unix.
12
12
13
13
For more information regarding the XDG user directories see:
14
14
https://wiki.archlinux.org/index.php/XDG_user_directories
15
+
16
+ For more information regarding the XDG state directory proposal see:
17
+ https://wiki.debian.org/XDGBaseDirectorySpecification#Proposal:_STATE_directory
18
+ https://lists.freedesktop.org/archives/xdg/2016-December/013803.html
15
19
*/
16
20
package xdg
17
21
@@ -21,14 +25,14 @@ var (
21
25
22
26
// DataHome defines the base directory relative to which user-specific
23
27
// data files should be stored. This directory is defined by the
24
- // environment variable $XDG_DATA_HOME . If this variable is not set,
28
+ // $XDG_DATA_HOME environment variable. If the variable is not set,
25
29
// a default equal to $HOME/.local/share should be used.
26
30
DataHome string
27
31
28
32
// DataDirs defines the preference-ordered set of base directories to
29
33
// search for data files in addition to the DataHome base directory.
30
- // This set of directories is defined by the environment variable
31
- // $XDG_DATA_DIRS . If this variable is not set, the default directories
34
+ // This set of directories is defined by the $XDG_DATA_DIRS environment
35
+ // variable . If the variable is not set, the default directories
32
36
// to be used are /usr/local/share and /usr/share, in that order. The
33
37
// DataHome directory is considered more important than any of the
34
38
// directories defined by DataDirs. Therefore, user data files should be
@@ -37,43 +41,43 @@ var (
37
41
38
42
// ConfigHome defines the base directory relative to which user-specific
39
43
// configuration files should be written. This directory is defined by
40
- // the environment variable $XDG_CONFIG_HOME . If this variable is not
44
+ // the $XDG_CONFIG_HOME environment variable. If the variable is not
41
45
// not set, a default equal to $HOME/.config should be used.
42
46
ConfigHome string
43
47
44
48
// ConfigDirs defines the preference-ordered set of base directories to
45
49
// search for configuration files in addition to the ConfigHome base
46
- // directory. This set of directories is defined by the environment
47
- // variable $XDG_CONFIG_DIRS . If this variable is not set, a default
48
- // equal to /etc/xdg should be used. The ConfigHome directory is
49
- // considered more important than any of the directories defined by
50
- // ConfigDirs. Therefore, user config files should be written
51
- // relative to the ConfigHome directory, if possible.
50
+ // directory. This set of directories is defined by the $XDG_CONFIG_DIRS
51
+ // environment variable . If the variable is not set, a default equal
52
+ // to /etc/xdg should be used. The ConfigHome directory is considered
53
+ // more important than any of the directories defined by ConfigDirs.
54
+ // Therefore, user config files should be written relative to the
55
+ // ConfigHome directory, if possible.
52
56
ConfigDirs []string
53
57
54
- // StateHome defines the base directory relative to which user-specific
55
- // data (volatile) files should be stored. This directory is defined by the
56
- // environment variable $XDG_STATE_HOME. If this variable is not set,
57
- // a default equal to ~/.local/state should be used.
58
- StateHome string
59
-
60
58
// CacheHome defines the base directory relative to which user-specific
61
59
// non-essential (cached) data should be written. This directory is
62
- // defined by the environment variable $XDG_CACHE_HOME . If this variable
60
+ // defined by the $XDG_CACHE_HOME environment variable. If the variable
63
61
// is not set, a default equal to $HOME/.cache should be used.
64
62
CacheHome string
65
63
66
64
// RuntimeDir defines the base directory relative to which user-specific
67
65
// non-essential runtime files and other file objects (such as sockets,
68
66
// named pipes, etc.) should be stored. This directory is defined by the
69
- // environment variable $XDG_RUNTIME_DIR . If this variable is not set,
67
+ // $XDG_RUNTIME_DIR environment variable. If the variable is not set,
70
68
// applications should fall back to a replacement directory with similar
71
69
// capabilities. Applications should use this directory for communication
72
70
// and synchronization purposes and should not place larger files in it,
73
71
// since it might reside in runtime memory and cannot necessarily be
74
72
// swapped out to disk.
75
73
RuntimeDir string
76
74
75
+ // StateHome defines the base directory relative to which user-specific
76
+ // volatile data files should be stored. This directory is defined by
77
+ // the non-standard $XDG_STATE_HOME environment variable. If the variable
78
+ // is not set, a default equal to ~/.local/state should be used.
79
+ StateHome string
80
+
77
81
// UserDirs defines the locations of well known user directories.
78
82
UserDirs UserDirectories
79
83
@@ -102,9 +106,9 @@ func Reload() {
102
106
ConfigDirs = baseDirs .config
103
107
CacheHome = baseDirs .cacheHome
104
108
RuntimeDir = baseDirs .runtime
109
+ StateHome = baseDirs .stateHome
105
110
FontDirs = baseDirs .fonts
106
111
ApplicationDirs = baseDirs .applications
107
- StateHome = baseDirs .stateHome
108
112
109
113
// Initialize user directories.
110
114
initUserDirs (Home )
@@ -120,16 +124,6 @@ func DataFile(relPath string) (string, error) {
120
124
return baseDirs .dataFile (relPath )
121
125
}
122
126
123
- // StateFile returns a suitable location for the specified data (volatile) file.
124
- // The relPath parameter must contain the name of the data file, and
125
- // optionally, a set of parent directories (e.g. appname/app.data).
126
- // If the specified directories do not exist, they will be created relative
127
- // to the base data directory. On failure, an error containing the
128
- // attempted paths is returned.
129
- func StateFile (relPath string ) (string , error ) {
130
- return baseDirs .stateFile (relPath )
131
- }
132
-
133
127
// ConfigFile returns a suitable location for the specified config file.
134
128
// The relPath parameter must contain the name of the config file, and
135
129
// optionally, a set of parent directories (e.g. appname/app.yaml).
@@ -160,6 +154,18 @@ func RuntimeFile(relPath string) (string, error) {
160
154
return baseDirs .runtimeFile (relPath )
161
155
}
162
156
157
+ // StateFile returns a suitable location for the specified state file. State
158
+ // files are usually volatile data files, not suitable to be stored relative
159
+ // to the $XDG_DATA_HOME directory.
160
+ // The relPath parameter must contain the name of the state file, and
161
+ // optionally, a set of parent directories (e.g. appname/app.state).
162
+ // If the specified directories do not exist, they will be created relative
163
+ // to the base state directory. On failure, an error containing the
164
+ // attempted paths is returned.
165
+ func StateFile (relPath string ) (string , error ) {
166
+ return baseDirs .stateFile (relPath )
167
+ }
168
+
163
169
// SearchDataFile searches for specified file in the data search paths.
164
170
// The relPath parameter must contain the name of the data file, and
165
171
// optionally, a set of parent directories (e.g. appname/app.data). If the
@@ -184,14 +190,6 @@ func SearchCacheFile(relPath string) (string, error) {
184
190
return baseDirs .searchCacheFile (relPath )
185
191
}
186
192
187
- // SearchStateFile searches for the specified file in the state search path.
188
- // The relPath parameter must contain the name of the state file, and
189
- // optionally, a set of parent directories (e.g. appname/app.state). If the
190
- // file cannot be found, an error specifying the searched path is returned.
191
- func SearchStateFile (relPath string ) (string , error ) {
192
- return baseDirs .searchStateFile (relPath )
193
- }
194
-
195
193
// SearchRuntimeFile searches for the specified file in the runtime search path.
196
194
// The relPath parameter must contain the name of the runtime file, and
197
195
// optionally, a set of parent directories (e.g. appname/app.pid). If the
@@ -200,6 +198,14 @@ func SearchRuntimeFile(relPath string) (string, error) {
200
198
return baseDirs .searchRuntimeFile (relPath )
201
199
}
202
200
201
+ // SearchStateFile searches for the specified file in the state search path.
202
+ // The relPath parameter must contain the name of the state file, and
203
+ // optionally, a set of parent directories (e.g. appname/app.state). If the
204
+ // file cannot be found, an error specifying the searched path is returned.
205
+ func SearchStateFile (relPath string ) (string , error ) {
206
+ return baseDirs .searchStateFile (relPath )
207
+ }
208
+
203
209
func init () {
204
210
Reload ()
205
211
}
0 commit comments