# Buggy code
def save(self):
    # type: () -> None
    # directory creation is lazy and after file filtering
    # to ensure we don't install empty dirs; empty dirs can't be
    # uninstalled.
    parent_dir = os.path.dirname(self.dest_path)
    ensure_dir(parent_dir)

    # When we open the output file below, any existing file is truncated
    # before we start writing the new contents. This is fine in most
    # cases, but can cause a segfault if pip has loaded a shared
    # object (e.g. from pyopenssl through its vendored urllib3)
    # Since the shared object is mmap'd an attempt to call a
    # symbol in it will then cause a segfault. Unlinking the file
    # allows writing of new contents while allowing the process to
    # continue to use the old copy.
    if os.path.exists(self.dest_path):
        os.unlink(self.dest_path)

    with self._zip_file.open(self.src_record_path) as f:
        with open(self.dest_path, "wb") as dest:
            shutil.copyfileobj(f, dest)

    zipinfo = self._zip_file.getinfo(self.src_record_path)
    if zip_item_is_executable(zipinfo):
        set_extracted_file_to_default_mode_plus_executable(self.dest_path)


# Traceback (KeyError)
Processing /home/sbi-local/.cache/pip/wheels/d3/64/58/cd7b9ff05f450397981fa37a0a279ed1d12cf763af16d8d7d7/mr.bob-0.1.2-py2-none-any.whl
Requirement already satisfied: Jinja2>=2.5.0 in /home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages (from mr.bob) (2.11.2)
Requirement already satisfied: six>=1.2.0 in /home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages (from mr.bob) (1.15.0)
Requirement already satisfied: setuptools in /home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages (from mr.bob) (44.1.1)
Requirement already satisfied: MarkupSafe>=0.23 in /home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages (from Jinja2>=2.5.0->mr.bob) (1.1.1)
Installing collected packages: mr.bob
ERROR: Exception:
Traceback (most recent call last):
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
status = self.run(options, args)
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
return func(self, options, args)
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/commands/install.py", line 421, in run
pycompile=options.compile,
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/req/__init__.py", line 90, in install_given_reqs
pycompile=pycompile,
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/req/req_install.py", line 831, in install
requested=self.user_supplied,
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/operations/install/wheel.py", line 829, in install_wheel
requested=requested,
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/operations/install/wheel.py", line 658, in _install_wheel
file.save()
File "/home/sbi-local/.virtualenvs/tempenv-7d78147760d35/lib/python2.7/site-packages/pip/_internal/operations/install/wheel.py", line 442, in save
with self._zip_file.open(self.src_record_path) as f:
File "/usr/lib/python2.7/zipfile.py", line 984, in open
zinfo = self.getinfo(name)
File "/usr/lib/python2.7/zipfile.py", line 932, in getinfo
'There is no item named %r in the archive' % name)
KeyError: "There is no item named u'mrbob/tests/templates/encodingc\\u030c/mapc\\u030ca/c\\u0301a.bob' in the archive"

# Fixed code
def save(self):
    # type: () -> None
    # directory creation is lazy and after file filtering
    # to ensure we don't install empty dirs; empty dirs can't be
    # uninstalled.
    parent_dir = os.path.dirname(self.dest_path)
    ensure_dir(parent_dir)

    # When we open the output file below, any existing file is truncated
    # before we start writing the new contents. This is fine in most
    # cases, but can cause a segfault if pip has loaded a shared
    # object (e.g. from pyopenssl through its vendored urllib3)
    # Since the shared object is mmap'd an attempt to call a
    # symbol in it will then cause a segfault. Unlinking the file
    # allows writing of new contents while allowing the process to
    # continue to use the old copy.
    if os.path.exists(self.dest_path):
        os.unlink(self.dest_path)

    zipinfo = self._getinfo()

    with self._zip_file.open(zipinfo) as f:
        with open(self.dest_path, "wb") as dest:
            shutil.copyfileobj(f, dest)

    if zip_item_is_executable(zipinfo):
        set_extracted_file_to_default_mode_plus_executable(self.dest_path)