Skip to content
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

Use sudo -H instead of sudo on Readme to avoid ruin the permissions of the pip cache folder #113

Merged
merged 1 commit into from
Mar 24, 2024

Conversation

luzfcb
Copy link
Contributor

@luzfcb luzfcb commented Mar 22, 2024

Motivation and Context

Assuming that I am a regular Linux user named luzfcb, with the HOME folder located in /home/luzfcb and the $HOME environment variable pointing to /home/luzfcb

sudo without -H modifier will run the command with root permissions, but using the $HOME environment variable of the current user ( not the root )
pip will use the $HOME environment variable to create a cache directory on /home/luzfcb/.cache/pip/, but all new files/directories will be created with root permission, and root-only read permission; that is, the luzfcb user has no write or read permission to some of the directories inside /home/luzfcb/.cache/pip/ .

sudo with the -H modifier will run the command with root permissions and use the root user's $HOME environment variable instead of the current user's $HOME.

So, if we use sudo with the -H modifier to run pip, the pip will use the $HOME environment variable of the root user to create a cache directory on /root/.cache/pip/, and all future sufferings will be avoided :-) .

Another option, to not use sudo with -H, is use pip with --no-cache-dir

Description

This pull-request adds the -H modifier the sudo when it is used the pip on the Readme

@regebro
Copy link
Member

regebro commented Mar 23, 2024

Hmm. Strange. In 30 years of using Linux I have never encountered this problem.

After digging some in the sudo manuals, I think possibly your /etc/sudoers have a Defaults !env_reset line in it, where the default is Defaults env_reset which should mean that sudo resets the env, including $HOME?

But I'm not sure, it's all a bit unclear, so that's just a guess.

@luzfcb
Copy link
Contributor Author

luzfcb commented Mar 23, 2024

I had this problem multiple times when I was new to Python and didn't understand how pip's cache works. At that time pip did not display a useful error message:

https://github.com/pypa/pip/blob/f5e4ee104e7b171a7cfb2843c9c602abf7a4e346/src/pip/_internal/cli/req_command.py#L220-L226 https://github.com/pypa/pip/blob/f5e4ee104e7b171a7cfb2843c9c602abf7a4e346/src/pip/_internal/cli/base_command.py#L163-L172

At that time, if I run sudo pip install foo-package and then pip install bar-package, you may have a permission problem because pip is trying to save some of the dependencies in the pip's cache subdirectory that does not have the same permissions as the current non-root user.

My intention with this pull-request is only to correct the use of sudo or pip to avoid introducing permissions problems in the non-root user's HOME pip cache directory

After digging some in the sudo manuals, I think possibly your /etc/sudoers have a Defaults !env_reset line in it, where the default is Defaults env_reset which should mean that sudo resets the env, including $HOME?

Although it may be a solution, I think it is beyond the scope of unoserver because it is a problem on pip itself and how it interacts with sudo, and that problem will not be resolved by pip at all because is also out of pip scope

@regebro
Copy link
Member

regebro commented Mar 23, 2024

That warning doesn't have anything to do with the .cache directory, and in fact pip checks the permissions, and if it encounters the error you have, it warns you, and that has seemingly been the case for 5 years. Pip warns against using sudo for other reasons, and recommends using a virtualenv, but the point of this readme is that a virtualenv will not work with unoserver (although it will work fine for the unoconvert and unocompare commands).

But then again, adding -H doesn't hurt, I guess.

@regebro regebro merged commit 21060c4 into unoconv:master Mar 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants