-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat XDG_CONFIG_HOME and $HOME/.config the same way #2084
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,9 +38,9 @@ func Get() string { | |
return homedir | ||
} | ||
|
||
// GetShortcutString returns the string that is shortcut to user's home directory | ||
// ShortcutString returns the string that is shortcut to user's home directory | ||
// in the native shell of the platform running on. | ||
func GetShortcutString() string { | ||
func ShortcutString() string { | ||
return "~" | ||
} | ||
|
||
|
@@ -52,7 +52,7 @@ func GetShortcutString() string { | |
// | ||
// See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html | ||
func StickRuntimeDirContents(files []string) ([]string, error) { | ||
runtimeDir, err := GetRuntimeDir() | ||
runtimeDir, err := RuntimeDir() | ||
if err != nil { | ||
// ignore error if runtimeDir is empty | ||
return nil, nil //nolint: nilerr | ||
|
@@ -101,11 +101,20 @@ func isWriteableOnlyByOwner(perm os.FileMode) bool { | |
return (perm & 0o722) == 0o700 | ||
} | ||
|
||
// GetConfigHome returns XDG_CONFIG_HOME. | ||
// GetConfigHome returns $HOME/.config and nil error if XDG_CONFIG_HOME is not set. | ||
// | ||
// See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html | ||
// GetConfigHome deprecated | ||
func GetConfigHome() (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not compile; was this intended to be |
||
rootlessConfigHomeDir, rootlessConfigHomeDirError = ConfigHome() | ||
if rootlessConfigHomeDirError == nil { | ||
_ = os.MkdirAll(rootlessConfigHomeDir, 0o700) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this function is deprecated and we intend to migrate all users, I don’t see that changing the existing one to not report failures is useful: that forces us to immediately review/migrate all users, negating the benefit of the deprecation and introduction of a new name for the new version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, right now, if the directory is missing, Shouldn’t all these functions, with their rare corner cases we don’t encounter on our workstations, have pretty good test coverage? I still mourn for tests lost in #1740 . |
||
} | ||
|
||
return rootlessConfigHomeDir, rootlessConfigHomeDirError | ||
} | ||
|
||
// ConfigHome returns XDG_CONFIG_HOME. (Deprecated) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Presumably this one is not deprecated. |
||
// ConfigHome returns $HOME/.config and nil error if XDG_CONFIG_HOME is not set. | ||
// See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html | ||
func ConfigHome() (string, error) { | ||
rootlessConfigHomeDirOnce.Do(func() { | ||
cfgHomeDir := os.Getenv("XDG_CONFIG_HOME") | ||
if cfgHomeDir == "" { | ||
|
@@ -115,33 +124,30 @@ func GetConfigHome() (string, error) { | |
rootlessConfigHomeDirError = fmt.Errorf("cannot resolve %s: %w", home, err) | ||
return | ||
} | ||
tmpDir := filepath.Join(resolvedHome, ".config") | ||
_ = os.MkdirAll(tmpDir, 0o700) | ||
st, err := os.Stat(tmpDir) | ||
if err != nil { | ||
rootlessConfigHomeDirError = err | ||
return | ||
} else if int(st.Sys().(*syscall.Stat_t).Uid) == os.Geteuid() { | ||
cfgHomeDir = tmpDir | ||
} else { | ||
rootlessConfigHomeDirError = fmt.Errorf("path %q exists and it is not owned by the current user", tmpDir) | ||
return | ||
} | ||
cfgHomeDir = filepath.Join(resolvedHome, ".config") | ||
} | ||
st, err := os.Stat(cfgHomeDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still not convinced that the stat adds value here. In fact if we keep the the stat then I see zero reason to change anything here because then most callers still have to ignore ENOENT errors which adds a lot of code and doesn't help the issue containers/podman#23818. Neither HomeDir() or GetCacheHome() validate permissions either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that propagating To be specific, we need some plan for the
We’ve had past painful experience with users who have I think if we ignore or special-case |
||
if err != nil { | ||
rootlessConfigHomeDirError = err | ||
return | ||
} else if int(st.Sys().(*syscall.Stat_t).Uid) != os.Geteuid() { | ||
rootlessConfigHomeDirError = fmt.Errorf("path %q exists and it is not owned by the current user", tmpDir) | ||
return | ||
} | ||
rootlessConfigHomeDir = cfgHomeDir | ||
}) | ||
|
||
return rootlessConfigHomeDir, rootlessConfigHomeDirError | ||
} | ||
|
||
// GetRuntimeDir returns a directory suitable to store runtime files. | ||
// RuntimeDir returns a directory suitable to store runtime files. | ||
// The function will try to use the XDG_RUNTIME_DIR env variable if it is set. | ||
// XDG_RUNTIME_DIR is typically configured via pam_systemd. | ||
// If XDG_RUNTIME_DIR is not set, GetRuntimeDir will try to find a suitable | ||
// If XDG_RUNTIME_DIR is not set, RuntimeDir will try to find a suitable | ||
// directory for the current user. | ||
// | ||
// See also https://standards.freedesktop.org/basedir-spec/latest/ar01s03.html | ||
func GetRuntimeDir() (string, error) { | ||
func RuntimeDir() (string, error) { | ||
var rootlessRuntimeDirError error | ||
|
||
rootlessRuntimeDirOnce.Do(func() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all these name changes…
Deprecated:
syntax so that tool make us migrate immediately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… all these name changes apart from the real semantic change WRT
ConfigHome
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rather not do the unrelated name changes, it just adds churn for no reason. If I look at a code and see the two different functions used I will always have to follow them to figure out if they are actual equal.