prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  pip.utils.filesystem.check_path_owner should treat group membership properly
  I have two users who share same .pip/cache directory: `a` and `b`. Both users are members of the group `pip`. There is third user, `pip` who is also member of group `pip` and that user handles all download and caching for users a and b. `.pip/cache` directory configured to have group writeable permission and sticky bit, to make sure all newly created files and folders are owned by group `pip`. 
  
  Function [check_path_owner](https://github.com/pypa/pip/blob/6.0.6/pip/utils/filesystem.py#L7) only checks if owner is same user, but it is somewhat wrong. You should check group membership as well. 
  
  Another option, is to create new command-line option, which will allow to ignore this check. 
  
  Either solution will work.
  
  
  </issue>
  <code>
  [start of pip/utils/filesystem.py]
  1 import os
  2 import os.path
  3 
  4 from pip.compat import get_path_uid
  5 
  6 
  7 def check_path_owner(path):
  8     # If we don't have a way to check the effective uid of this process, then
  9     # we'll just assume that we own the directory.
  10     if not hasattr(os, "geteuid"):
  11         return True
  12 
  13     previous = None
  14     while path != previous:
  15         if os.path.lexists(path):
  16             # Actually do the ownership check
  17             try:
  18                 if get_path_uid(path) != os.geteuid():
  19                     return False
  20             except OSError:
  21                 return False
  22             return True
  23         else:
  24             previous, path = path, os.path.dirname(path)
  25
  [end of pip/utils/filesystem.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pip/utils/filesystem.py b/pip/utils/filesystem.py
  --- a/pip/utils/filesystem.py
  +++ b/pip/utils/filesystem.py
  @@ -13,12 +13,16 @@
       previous = None
       while path != previous:
           if os.path.lexists(path):
  -            # Actually do the ownership check
  -            try:
  -                if get_path_uid(path) != os.geteuid():
  +            # 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
  -            except OSError:
  -                return False
  -            return True
  +                return path_uid == 0
  +            else:
  +                return os.access(path, os.W_OK)
           else:
               previous, path = path, os.path.dirname(path)
  
verification_info: {"golden_diff": "diff --git a/pip/utils/filesystem.py b/pip/utils/filesystem.py\n--- a/pip/utils/filesystem.py\n+++ b/pip/utils/filesystem.py\n@@ -13,12 +13,16 @@\n     previous = None\n     while path != previous:\n         if os.path.lexists(path):\n-            # Actually do the ownership check\n-            try:\n-                if get_path_uid(path) != os.geteuid():\n+            # Check if path is writable by current user.\n+            if os.geteuid() == 0:\n+                # Special handling for root user in order to handle properly\n+                # cases where users use sudo without -H flag.\n+                try:\n+                    path_uid = get_path_uid(path)\n+                except OSError:\n                     return False\n-            except OSError:\n-                return False\n-            return True\n+                return path_uid == 0\n+            else:\n+                return os.access(path, os.W_OK)\n         else:\n             previous, path = path, os.path.dirname(path)\n", "issue": "pip.utils.filesystem.check_path_owner should treat group membership properly\nI have two users who share same .pip/cache directory: `a` and `b`. Both users are members of the group `pip`. There is third user, `pip` who is also member of group `pip` and that user handles all download and caching for users a and b. `.pip/cache` directory configured to have group writeable permission and sticky bit, to make sure all newly created files and folders are owned by group `pip`. \n\nFunction [check_path_owner](https://github.com/pypa/pip/blob/6.0.6/pip/utils/filesystem.py#L7) only checks if owner is same user, but it is somewhat wrong. You should check group membership as well. \n\nAnother option, is to create new command-line option, which will allow to ignore this check. \n\nEither solution will work.\n\n", "before_files": [{"content": "import os\nimport os.path\n\nfrom pip.compat import get_path_uid\n\n\ndef check_path_owner(path):\n    # If we don't have a way to check the effective uid of this process, then\n    # we'll just assume that we own the directory.\n    if not hasattr(os, \"geteuid\"):\n        return True\n\n    previous = None\n    while path != previous:\n        if os.path.lexists(path):\n            # Actually do the ownership check\n            try:\n                if get_path_uid(path) != os.geteuid():\n                    return False\n            except OSError:\n                return False\n            return True\n        else:\n            previous, path = path, os.path.dirname(path)\n", "path": "pip/utils/filesystem.py"}]}