Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 600626 - sys-apps/portage: apply_recursive_permissions function could use os.fwalk to avoid "OSError: [Errno 63] File name too long"
Summary: sys-apps/portage: apply_recursive_permissions function could use os.fwalk to ...
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Portage team
Depends on:
Reported: 2016-11-23 21:35 UTC by Zac Medico
Modified: 2016-12-26 21:23 UTC (History)
1 user (show)

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 2016-11-23 21:35:12 UTC
As reported in bug 600576, it's possible for apply_recursive_permissions to raise "OSError: [Errno 63] File name too long" if extremely long paths are nested within a directory structure.

It seems that portage can be fixed to handle this by making the apply_recursive_permissions function use os.fwalk and similar functions that use file descriptors instead of paths. I've tested with python-3.5.2, and os.fwalk successfully traversed all of /var/tmp/portage/app-arch/libarchive-3.2.2/temp. It worked with a string argument, but failed with a bytes argument as reported in

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.5/", line 519, in fwalk
    yield from _fwalk(topfd, top, topdown, onerror, follow_symlinks)
  File "/usr/lib64/python3.5/", line 562, in _fwalk
    dirpath = path.join(toppath, name)
  File "/usr/lib64/python3.5/", line 89, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib64/python3.5/", line 145, in _check_arg_types
    raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

If we can't use a bytes argument, then it's going to fail if any of the paths aren't encoded with the encoding that python expects.