comparison planemo/lib/python3.7/site-packages/pip/_internal/utils/filesystem.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 import os
2 import os.path
3
4 from pip._internal.utils.compat import get_path_uid
5
6
7 def check_path_owner(path):
8 # type: (str) -> bool
9 # If we don't have a way to check the effective uid of this process, then
10 # we'll just assume that we own the directory.
11 if not hasattr(os, "geteuid"):
12 return True
13
14 previous = None
15 while path != previous:
16 if os.path.lexists(path):
17 # Check if path is writable by current user.
18 if os.geteuid() == 0:
19 # Special handling for root user in order to handle properly
20 # cases where users use sudo without -H flag.
21 try:
22 path_uid = get_path_uid(path)
23 except OSError:
24 return False
25 return path_uid == 0
26 else:
27 return os.access(path, os.W_OK)
28 else:
29 previous, path = path, os.path.dirname(path)
30 return False # assume we don't own the path