@@ -7,11 +7,12 @@ import (
77 "strings"
88)
99
10- // GetRuntimeDir returns XDG_RUNTIME_DIR.
11- // XDG_RUNTIME_DIR is typically configured via pam_systemd.
12- // GetRuntimeDir returns non-nil error if XDG_RUNTIME_DIR is not set .
10+ // GetRuntimeDir returns [ XDG_RUNTIME_DIR]. It returns a non-nil error if
11+ // XDG_RUNTIME_DIR is not set. XDG_RUNTIME_DIR is typically configured via
12+ // [pam_systemd] .
1313//
14- // See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
14+ // [XDG_RUNTIME_DIR]: https://specifications.freedesktop.org/basedir/0.8/#variables
15+ // [pam_systemd]: https://man7.org/linux/man-pages/man8/pam_systemd.8.html
1516func GetRuntimeDir () (string , error ) {
1617 if xdgRuntimeDir := os .Getenv ("XDG_RUNTIME_DIR" ); xdgRuntimeDir != "" {
1718 return xdgRuntimeDir , nil
@@ -20,12 +21,15 @@ func GetRuntimeDir() (string, error) {
2021}
2122
2223// StickRuntimeDirContents sets the sticky bit on files that are under
23- // XDG_RUNTIME_DIR, so that the files won't be periodically removed by the system.
24+ // [XDG_RUNTIME_DIR], so that the files won't be periodically removed by the
25+ // system.
2426//
25- // StickyRuntimeDir returns slice of sticked files.
26- // StickyRuntimeDir returns nil error if XDG_RUNTIME_DIR is not set.
27+ // It returns a slice of sticked files as absolute paths. The list of files may
28+ // be empty (nil) if XDG_RUNTIME_DIR is not set, in which case no error is returned.
29+ // StickyRuntimeDir produces an error when failing to resolve the absolute path
30+ // for the returned files.
2731//
28- // See also https://standards .freedesktop.org/basedir-spec/latest/ar01s03.html
32+ // [XDG_RUNTIME_DIR]: https://specifications .freedesktop.org/basedir/0.8/#variables
2933func StickRuntimeDirContents (files []string ) ([]string , error ) {
3034 runtimeDir , err := GetRuntimeDir ()
3135 if err != nil {
@@ -62,11 +66,12 @@ func stick(f string) error {
6266 return os .Chmod (f , m )
6367}
6468
65- // GetDataHome returns XDG_DATA_HOME.
66- // GetDataHome returns $HOME/.local/share and nil error if XDG_DATA_HOME is not set.
67- // If HOME and XDG_DATA_HOME are not set, getpwent(3) is consulted to determine the users home directory.
69+ // GetDataHome returns [ XDG_DATA_HOME] or $HOME/.local/share and a nil error if
70+ // [XDG_DATA_HOME] is not set. If neither HOME nor XDG_DATA_HOME are set,
71+ // [ getpwent(3)] is consulted to determine the users home directory.
6872//
69- // See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
73+ // [XDG_DATA_HOME]: https://specifications.freedesktop.org/basedir/0.8/#variables
74+ // [getpwent(3)]: https://man7.org/linux/man-pages/man3/getpwent.3.html
7075func GetDataHome () (string , error ) {
7176 if xdgDataHome := os .Getenv ("XDG_DATA_HOME" ); xdgDataHome != "" {
7277 return xdgDataHome , nil
@@ -78,11 +83,12 @@ func GetDataHome() (string, error) {
7883 return filepath .Join (home , ".local" , "share" ), nil
7984}
8085
81- // GetConfigHome returns XDG_CONFIG_HOME.
82- // GetConfigHome returns $HOME/.config and nil error if XDG_CONFIG_HOME is not set.
83- // If HOME and XDG_CONFIG_HOME are not set, getpwent(3) is consulted to determine the users home directory.
86+ // GetConfigHome returns [ XDG_CONFIG_HOME] or $HOME/.config and a nil error if
87+ // XDG_CONFIG_HOME is not set. If neither HOME nor XDG_CONFIG_HOME are set,
88+ // [ getpwent(3)] is consulted to determine the users home directory.
8489//
85- // See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
90+ // [XDG_CONFIG_HOME]: https://specifications.freedesktop.org/basedir/0.8/#variables
91+ // [getpwent(3)]: https://man7.org/linux/man-pages/man3/getpwent.3.html
8692func GetConfigHome () (string , error ) {
8793 if xdgConfigHome := os .Getenv ("XDG_CONFIG_HOME" ); xdgConfigHome != "" {
8894 return xdgConfigHome , nil
@@ -94,8 +100,10 @@ func GetConfigHome() (string, error) {
94100 return filepath .Join (home , ".config" ), nil
95101}
96102
97- // GetLibHome returns $HOME/.local/lib
98- // If HOME is not set, getpwent(3) is consulted to determine the users home directory.
103+ // GetLibHome returns $HOME/.local/lib. If HOME is not set, [getpwent(3)] is
104+ // consulted to determine the users home directory.
105+ //
106+ // [getpwent(3)]: https://man7.org/linux/man-pages/man3/getpwent.3.html
99107func GetLibHome () (string , error ) {
100108 home := Get ()
101109 if home == "" {
@@ -104,8 +112,10 @@ func GetLibHome() (string, error) {
104112 return filepath .Join (home , ".local/lib" ), nil
105113}
106114
107- // GetLibexecHome returns $HOME/.local/libexec
108- // If HOME is not set, getpwent(3) is consulted to determine the users home directory.
115+ // GetLibexecHome returns $HOME/.local/libexec. If HOME is not set,
116+ // [getpwent(3)] is consulted to determine the users home directory.
117+ //
118+ // [getpwent(3)]: https://man7.org/linux/man-pages/man3/getpwent.3.html
109119func GetLibexecHome () (string , error ) {
110120 home := Get ()
111121 if home == "" {
0 commit comments