-
-
Notifications
You must be signed in to change notification settings - Fork 81
Optionally redirect user_*_dir() calls to site_*_dir() for root on Unix #213
Description
This is a follow-up to #188 concerning the second suggestion I made there:
platformdirs.user_runtime_dir()currently yields/run/user/0/…for root on Unix. While not strictly false, this is a rather uncommon result; for root I'd rather expect just/run/….
Due to this @kemzeb just recently added platformdirs.site_runtime_dir() yielding /run/… on Unix (thank you @kemzeb! ❤️). I absolutely think that this is the right approach. However, platformdirs.user_runtime_dir() still yields /run/user/0/… for root on Unix - which is not wrong (it might be the correct answer, see #188), but unexpected.
This gets crucial for software that can run as both unprivileged users, and root, like Borg. For unprivileged users platformdirs.user_runtime_dir() is always the right answer, but for root it's usually platformdirs.site_runtime_dir(). I believe that this is true for most software that can run as both unprivileged users, and root:
[…] root is different: Software running as root is often intentionally NOT bound to root being logged in - in many systems root can't login at all. This is due to root's special role in Unix and a major difference to any other user. […] This doesn't mean that there might not indeed be software whose lifetime is bound to root being logged in [(i.e.
platformdirs.user_runtime_dir()is the right answer for root, too)] - but that's the exception rather than the rule.AFAIK
platformdirsdoesn't address root's special role in Unix […] right now, but it should.
To better account for root's special role on Unix I'd like to suggest the following:
As additional feature it might be helpful to add a global switch (disabled by default) which basically redirects calls to
platformdirs.user_*_dir()to theirplatformdirs.site_*_dir()equivalent (i.e. not just foruser_runtime_dir(), but config, cache, state, … too) for root unless stated otherwise (i.e. add a option to each method next to the global switch).
Even though I believe that most software would want to enable this global switch, I suggest disabling it by default to preserve BC. However, we should document this and the switch's usage.
What are your opinions on this?
Just to make this clear: One can easily implement root's special role in the software using platformdirs, i.e. add such a switch. Thus it's definitely no major issue. However, if you decide not to implement such a switch I'd strongly vote for at least documenting root's special role in Unix and that most projects rather want to use platformdirs.site_*_dir() for root.
Cc: @ThomasWaldmann