Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 692922 - sys-apps/portage: prepare_build_dirs shutil.rmtree PermissionError for unprivileged user following chmod a-w
Summary: sys-apps/portage: prepare_build_dirs shutil.rmtree PermissionError for unpriv...
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
Depends on:
Reported: 2019-08-26 20:17 UTC by Zac Medico
Modified: 2020-02-08 11:29 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Zac Medico gentoo-dev 2019-08-26 20:17:40 UTC
When working with an ebuild where some directories created under ${HOME} had the writable bits removed, I found that it triggered a PermissionError in shutil.rmtree. Then problem is easily demonstrated as follows:

> $ mkdir -p /tmp/foo/bar/baz
> $ chmod a-w /tmp/foo/bar/baz /tmp/foo/bar
> $ python3.7
> Python 3.7.0 (default, Feb 20 2019, 18:25:13) 
> [GCC 7.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import shutil
> >>> shutil.rmtree('/tmp/foo')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python3.7/", line 485, in rmtree
>     _rmtree_safe_fd(fd, path, onerror)
>   File "/usr/lib/python3.7/", line 423, in _rmtree_safe_fd
>     _rmtree_safe_fd(dirfd, fullname, onerror)
>   File "/usr/lib/python3.7/", line 427, in _rmtree_safe_fd
>     onerror(os.rmdir, fullname, sys.exc_info())
>   File "/usr/lib/python3.7/", line 425, in _rmtree_safe_fd
>     os.rmdir(, dir_fd=topfd)
> PermissionError: [Errno 13] Permission denied: 'baz'

Though this issue could apply to all shutil.rmtree calls, it's most problematic when removing files/directories created by random processes, like in prepare_build_dirs where it attempts to cleanup the temporary ${HOME} dir.
Comment 1 Zac Medico gentoo-dev 2019-11-30 02:59:45 UTC
Similar issue with gitea-1.9.5, ebuild gitea-1.9.5.ebuild prepare clean results in lots of messages like:
> rm: cannot remove '/var/tmp/portage/www-apps/gitea-1.9.5/work/gitea-1.9.5/pkg/mod/': Permission denied
> rm: cannot remove '/var/tmp/portage/www-apps/gitea-1.9.5/work/gitea-1.9.5/pkg/mod/': Permission denied