-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Optionally redirect user_*_dir()
calls to site_*_dir()
for root on Unix
#213
Comments
Ho would this global switch work? |
I don't really have an exact implementation in mind. The idea is that users can change it once (i.e. once for their app) and aren't required to declare it on every invocation. My initial idea (at the time I created #188) was using a class attribute: >>> import os
>>> os.getuid()
0
>>> from platformdirs import PlatformDirs
>>> PlatformDirs.use_site_dirs_for_root = True
>>> PlatformDirs.site_runtime_dir("SuperApp", "Acme")
'/run/SuperApp'
>>> PlatformDirs.user_runtime_dir("SuperApp", "Acme")
'/run/SuperApp'
>>> PlatformDirs.user_runtime_dir("SuperApp", "Acme", use_site_dirs_for_root=False)
'/run/user/0/SuperApp' However, as I said, I'm indifferent about the concrete implementation. >>> from platformdirs import PlatformDirs
>>> dirs = PlatformDirs("SuperApp", "Acme", use_site_dirs_for_root=True)
>>> dirs.user_runtime_dir
'/var/run/SuperApp'
>>> dirs.site_runtime_dir
'/var/run/SuperApp' It should be what you think fits best. |
platformdirs.user_*_dir()
calls to platformdirs.site_*_dir()
for root on Unixuser_*_dir()
calls to site_*_dir()
for root on Unix
I would love this too. The permissions situation might be tricky if you expect non-root users to be able to write to those dirs later, who should own them if root creates them for example? I think it's worth figuring out and implementing though, as it would be very useful to be able to setup site stuff by running a package as root, and then continue using it as other users. |
This is a follow-up to #188 concerning the second suggestion I made there:
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 usuallyplatformdirs.site_runtime_dir()
. I believe that this is true for most software that can run as both unprivileged users, and root:To better account for root's special role on Unix I'd like to suggest the following:
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 useplatformdirs.site_*_dir()
for root.Cc: @ThomasWaldmann
The text was updated successfully, but these errors were encountered: