本文整理汇总了Python中pip._internal.compat.get_path_uid方法的典型用法代码示例。如果您正苦于以下问题:Python compat.get_path_uid方法的具体用法?Python compat.get_path_uid怎么用?Python compat.get_path_uid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.compat
的用法示例。
在下文中一共展示了compat.get_path_uid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_path_owner
# 需要导入模块: from pip._internal import compat [as 别名]
# 或者: from pip._internal.compat import get_path_uid [as 别名]
def check_path_owner(path):
# If we don't have a way to check the effective uid of this process, then
# we'll just assume that we own the directory.
if not hasattr(os, "geteuid"):
return True
previous = None
while path != previous:
if os.path.lexists(path):
# Check if path is writable by current user.
if os.geteuid() == 0:
# Special handling for root user in order to handle properly
# cases where users use sudo without -H flag.
try:
path_uid = get_path_uid(path)
except OSError:
return False
return path_uid == 0
else:
return os.access(path, os.W_OK)
else:
previous, path = path, os.path.dirname(path)